From 6d904fdfc4991576fa70b24ea9cf470e2d11ecaf Mon Sep 17 00:00:00 2001 From: darkf Date: Mon, 21 Oct 2013 13:18:25 -0700 Subject: [PATCH] AST representation of functions shouldn't use a list as they only contain one expression --- ast.hs | 2 +- interp.hs | 6 +++--- parser.hs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ast.hs b/ast.hs index 64aa245..f28cf8f 100644 --- a/ast.hs +++ b/ast.hs @@ -13,7 +13,7 @@ data AST = Add AST AST | Defun String AST | Def String AST | Var String - | Lambda [(Pattern, [AST])] + | Lambda [(Pattern, AST)] | Call String [AST] | UnitConst | Cons AST AST diff --git a/interp.hs b/interp.hs index 70d4b4c..52879c2 100644 --- a/interp.hs +++ b/interp.hs @@ -22,7 +22,7 @@ data Value = IntV Integer | StreamV Int | ListV [Value] | Builtin BIF - | FnV [(Pattern, [AST])] -- pattern->body bindings + | FnV [(Pattern, AST)] -- pattern->body bindings deriving (Eq) type Env = M.Map String Value -- an environment @@ -85,7 +85,7 @@ _itos (IntV i) = return $ StrV $ show i _itos v = error $ "itos: not an int: " ++ show v initialState = ([stdout, stdin], - M.fromList [("id", FnV [(VarP "x", [Var "x"])]), + M.fromList [("id", FnV [(VarP "x", Var "x")]), ("stdout", StreamV 0), ("putstr", Builtin $ BIF _putstr), ("putstrln", Builtin $ BIF (\x -> _putstr $ x +$ StrV "\n")), @@ -205,7 +205,7 @@ apply (FnV pats) arg = do (s,env) <- get put (s, M.union env' env) - foldr1 (>>) $ map eval body + eval body Nothing -> -- doesn't satisfy this pattern apply' xs diff --git a/parser.hs b/parser.hs index f660a28..32aba48 100644 --- a/parser.hs +++ b/parser.hs @@ -99,7 +99,7 @@ rewriteFun (FunDef name (patterns, body)) = Defun name lam where -- curry it - lam = foldr (\pat lam -> Lambda [(pat, [lam])]) body patterns + lam = foldr (\pat lam -> Lambda [(pat, lam)]) body patterns call = do name <- identifier