Skip to content

Instantly share code, notes, and snippets.

@SAdams601
Last active February 21, 2018 16:26
Show Gist options
  • Save SAdams601/a2a6e448f52840e6a7696f394d6688bd to your computer and use it in GitHub Desktop.
Save SAdams601/a2a6e448f52840e6a7696f394d6688bd to your computer and use it in GitHub Desktop.
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