Created
January 15, 2016 00:51
-
-
Save AphonicChaos/a8c015e43d7ba666c0bc 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 #-} | |
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 |
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
module Main where | |
import Spell | |
import Player | |
import Foo | |
main :: IO () | |
main = print' program |
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
moveForward(); | |
moveForward(); | |
destroyBlock(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment