(This is intended as a simplification of the problem I actually need to solve.)<br><br>I'm trying to implement the lambda calculus (with CBV evaluation) using the "syntactic" package, in such a way that a simple extension is also simple to implement.<br>
<br>I am stuck on the fact that it seems that the Value type needs to be parametrized over the Expr type and I can't seem to figure out how to do it.<br><br>I've read <a href="http://www.haskell.org/pipermail/haskell-cafe/2011-May/091770.html">this post</a> from the archives, but I still seem to be missing something.<br>
<br>Does anyone have any suggestions?<br><br>> -- Lambda calculus<br>> type Ident = String<br>> data Value = VLam Ident Expr<br>> data Expr = Var Ident | Lam Ident Expr | App Expr Expr<br>> eval :: Expr -> Value<br>
> eval e =<br>> case e of<br clear="all">> Var _ -> error "not closed"<br>> Lam i e' -> VLam i e'<br>> App e1 e2 -><br>> case eval e1 of<br>> Lam i e' -> subst e' (eval e2) i<br>
> _ -> error "illegal application"<br><br>> -- Lambda calculus with integers and addition<br>> data Value = VLam Ident Expr | VInt Integer<br>> data Expr = Var Ident | Lam Ident Expr | App Expr Expr | Plus Expr Expr<br>
> eval e =<br>> case e of<br>> ...<br>> Plus e1 e2 -><br>> case (eval e1, eval e2) of<br>> (VInt x1, VInt x2) -> VInt $ x1 + x2<br>> _ -> error "illegal addition"<br>
<br>-- <br><div dir="ltr"><div> Alex R</div></div><br>