Created
April 4, 2013 04:29
-
-
Save jsyeo/5307831 to your computer and use it in GitHub Desktop.
Lambda calculus in less than 20 lines of code.
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 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