I've been working on implementing games in Haskell. Specifically, rules-driven board/card games.
When these games run, they often need to ask a player to make a move. This involves interacting with the outside world in some way. The most obvious way to do this is to embed your computation in the IO Monad:
type Game a = IO a
(
Read more... )
Comments 9
Reply
In particular,
( ... )
Reply
Reply
BTW, this reminds me of various encodings of things like state or regions using polymorphism, like in a paper by Fluet and Morrisett (ICFP '04, I think).
Reply
I wrote a strongly typed lambda-calculus interpreter using GADTs; it's a tougher problem than it looks. Give it a shot if you feel like a little thought-challenge, starting with this:
data NDecl -- no variables
data Decl a as -- top-level variable of type a, along with more variables
type Name = String
data Expr ty dcl where
EPrim :: Prim ty -> Expr ty dcl -- optional (advanced implementation)
EAp :: Expr (t0->t1) dcl -> Expr t0 dcl -> Expr t1 dcl
EFix :: Expr (ty->ty) dcl -> Expr ty dcl
EVar :: Expr ty (Decl ty dcl)
ELam :: Name -> Expr ty (Decl a dcl) -> Expr (a -> ty) dcl
EPush :: Expr ty dcl -> Expr ty (Decl ty2 dcl)
type NExpr ty = Expr ty NDecl
expr_id :: NExpr (x -> x)
expr_id = ELam "x" EVar
expr_const :: NExpr (x -> y -> x)
expr_const = ELam "x" (ELam "y" (EPush EVar))
eval :: ExprNoFreeVars ty -> ty
eval expr = ?Hint: I ( ... )
Reply
Reply
I should take a shot at the your example, though, since I haven't actually used GADTs as implemented in recent ghc's.
Reply
I'm trying to solve some of the project euler problems, and I'm trying to use the backtracking of the list monad to find solutions (working on 185 right now). It's cool to have a completely different way to think about control flow.
Reply
Leave a comment