Created
August 28, 2015 18:13
-
-
Save saevarb/2a388c7bd45c0c25909d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveFunctor #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
import Control.Monad.State | |
import Control.Monad.Trans.Free | |
data Turtle n | |
= MoveForward n | |
| MoveBackwards n | |
| TurnLeft n | |
| TurnRight n | |
| MarkSquare n | |
| Echo String n | |
| Stop n | |
deriving (Show, Eq, Functor) | |
data TurtleState = TurtleState String | |
type Program = Free Turtle | |
echo :: String -> Program () | |
echo x = liftF (Echo x ()) | |
program :: Program () | |
program = do | |
echo "foobar" | |
run :: Program a -> IO () | |
run prg = | |
case runFree prg of | |
Free (Echo s n) -> putStrLn s >> run n | |
main :: IO () | |
main = undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment