Skip to content

Instantly share code, notes, and snippets.

@mpage
Created January 26, 2015 07:40
Show Gist options
  • Select an option

  • Save mpage/084a26befcd76d697879 to your computer and use it in GitHub Desktop.

Select an option

Save mpage/084a26befcd76d697879 to your computer and use it in GitHub Desktop.
Evaluator for a simple ast. A little mind blowing.
import Data.Map
import Control.Monad
number = return
add = liftM2 (+)
multiply = liftM2 (*)
variable = findWithDefault 0
environment = fromList [("a",3), ("b",4), ("c",7)]
expressionTree = add (variable "a") (multiply (number 2) (variable "b"))
main = print $ expressionTree environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment