Last active
February 21, 2018 16:26
-
-
Save SAdams601/a2a6e448f52840e6a7696f394d6688bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type EvalSt = State Env | |
eval :: Expr -> EvalSt Int | |
eval (Var v) = do | |
env <- get | |
return (head [val |(x,val) <- env, x == v]) | |
eval (N n) = return n | |
eval (Add e1 e2) = do | |
v1 <- eval e1 | |
v2 <- eval e2 | |
return (v1+v2) | |
eval (Assign x e) = do | |
v <- eval e | |
put $ (x,v):env | |
return v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment