Open eloign opened 2 years ago
Basically, we need to add indentation parsing for: Data declaration Let construction Type declaration If construction Application e t. c.
LamCase [Alt]
Evaluation:
' y = 4 x = 5
main = print x '
go through: 1) y = Nothing x = Nothing
main = Nothing
2) y = Just 5 x = Nothing
main = Nothing
3) e t. c.
Another Idea
Make an extension like this:
x = 5 y = 6
main = print x
1)
x = Left (Lit 5) y = Left (Lit 6)
main = Left (App (Var "print") (Var "x"))
2)
x = Right (LitV 5) y = Left (Lit 6)
main = Right (ConV "IO" [])
Other example:
y = x x = 5
main = print y
1)
y = Left (Var "x") x = Left (Lit 5)
main = Left (App (Var "print") (Var "y"))
2)
y = Right (LitV 5) x = Right (LitV 5)
main = Right ...
and make it with corresponding substitutions in decl environment
Add: LamCaseV and LamCase
LamCase [Alt]
LamCaseV Env ...
LamCase [Alt] restricts: 1) the number of arguments is always the same 2) the number of arguments can be null
f = 5
\case of -> 5
f a = 4
\case a of a -> 4
1)
\a -> \b -> case a, b of ...patterns and stuff
2) or FunApp Name [Value]
evalExpr e en = case exps alts -> case exps of [] -> go exps
go (x:xs) = case x of ([],Nothing,exp) -> evalExpr exp ([],Just c, exp) -> do cond <- evalExpr c if cond == (ConV "True" []) then evalExpr exp else go xs
other: match exps alts ...
maybe add: f | a = 5 | b = ... |
---|
either everything impure, either try to invent something, either add laziness
LamV Env Pattern Expr LamCase [Alt]