Skip to content

Instantly share code, notes, and snippets.

@saevarb
Created August 28, 2015 18:13
Show Gist options
  • Save saevarb/2a388c7bd45c0c25909d to your computer and use it in GitHub Desktop.
Save saevarb/2a388c7bd45c0c25909d to your computer and use it in GitHub Desktop.
{-# 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