Skip to content

Instantly share code, notes, and snippets.

@AphonicChaos
Created January 15, 2016 00:51
Show Gist options
  • Save AphonicChaos/a8c015e43d7ba666c0bc to your computer and use it in GitHub Desktop.
Save AphonicChaos/a8c015e43d7ba666c0bc to your computer and use it in GitHub Desktop.
{-# Language DeriveFunctor #-}
module Command where
import Control.Monad (replicateM_)
import Control.Monad.Free
(|>) :: (Monad m) => Int -> m a -> m ()
(|>) = replicateM_
data CommandF a = MoveForward a | DestroyBlock a deriving (Functor)
type Command = Free CommandF ()
moveForward :: Command
moveForward = liftF $ MoveForward ()
destroyBlock :: Command
destroyBlock = liftF $ DestroyBlock ()
program = do
2 |> do
moveForward
destroyBlock
display :: Command -> String
display (Free m@(MoveForward next)) = "moveForward()\n" ++ display next
display (Free d@(DestroyBlock next)) = "destroyBlock()\n" ++ display next
display (Pure ()) = ""
print' = putStrLn . display
module Main where
import Spell
import Player
import Foo
main :: IO ()
main = print' program
moveForward();
moveForward();
destroyBlock();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment