AST representation of functions shouldn't use a list as they only contain one expression

This commit is contained in:
darkf 2013-10-21 13:18:25 -07:00
parent 700c5be701
commit 6d904fdfc4
3 changed files with 5 additions and 5 deletions

2
ast.hs
View File

@ -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

View File

@ -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

View File

@ -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