Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created January 20, 2017 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/ce001c284883728133cb773be7e643e8 to your computer and use it in GitHub Desktop.
Save deque-blog/ce001c284883728133cb773be7e643e8 to your computer and use it in GitHub Desktop.
eval :: Env -> Expr -> Int
eval env = cata algebra where
algebra (Cst n) = n
algebra (Var x) = env Map.! x
algebra (Op Add xs) = sum xs
algebra (Op Mul xs) = product xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment