Skip to content

Instantly share code, notes, and snippets.

@jsyeo
Created April 4, 2013 04:29
Show Gist options
  • Save jsyeo/5307831 to your computer and use it in GitHub Desktop.
Save jsyeo/5307831 to your computer and use it in GitHub Desktop.
Lambda calculus in less than 20 lines of code.
type Var = String
type Env = [(Var, Term)]
data Term = Var Var
| Lambda Var Term
| Apply Term Term
| Closure Env Var Term
deriving(Show)
varLookup ((v,t):env) var = if var == v then
t
else varLookup env var
extend env v t = ((v,t):env)
eval env (Var v) = varLookup env v
eval env (Lambda v t) = Closure env v t
eval env (Apply t0 t1) = apply (eval env t0) (eval env t1)
apply (Closure e v t0) t1 = eval (extend e v t1) t0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment