Skip to content

Instantly share code, notes, and snippets.

@quantumman
Created November 18, 2012 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quantumman/4104609 to your computer and use it in GitHub Desktop.
Save quantumman/4104609 to your computer and use it in GitHub Desktop.
{-# LANGUAGE DeriveFunctor #-}
import Control.Monad.Free
import Control.Applicative
data Card
data PlayingF next
= Draw (Card -> next)
| Discard Card next
| Play Card next
| Interactive (Operation -> next)
deriving (Functor)
data Operation
= Select Card
| Next
type Playing = Free PlayingF
interpret :: Playing next -> IO ()
interpret (Pure a) = return ()
interpret (Free playing) = case playing of
Draw f -> do
card <- getCardFromDeck
interpret $ f card
Discard card next -> do
putCardOnDiscardPile
interpret next
Play card next -> do
resolve card
interpret next
Interactive f -> do
operation <- toOperation <$> readLn
interpret $ f operation
where
getCardFromDeck = undefined
putCardOnDiscardPile = undefined
resolve = undefined
toOperation :: String -> Operation
toOperation = undefined
draw :: Playing Card
draw = liftF $ Draw id
dicard :: Card -> Playing ()
dicard card = liftF $ Discard card ()
play :: Card -> Playing ()
play card = liftF $ Play card ()
interactive :: Playing Operation
interactive = liftF $ Interactive id
mainPhase = do
input <- interactive
case input of
Select card -> do
play card
mainPhase
_ -> secondPhase
secondPhase = undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment