Created
November 18, 2012 11:18
-
-
Save quantumman/4104609 to your computer and use it in GitHub Desktop.
This file contains 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 #-} | |
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