Skip to content

Instantly share code, notes, and snippets.

@fumieval
Created May 26, 2012 12:47
Show Gist options
  • Save fumieval/2793825 to your computer and use it in GitHub Desktop.
Save fumieval/2793825 to your computer and use it in GitHub Desktop.
The essence of Lazy Z compiler
data ExprP = Var String | Apply ExprP ExprP | Lambda String ExprP -- lambda calculus expression
data Expr = I | K | S | Expr :$ Expr | Free String -- combinatory expression
compile :: ExprP -> Expr
compile (Apply f x) = compile f :$ compile x
compile (Lambda p e) = bindee p $ compile e
compile (Var i) = Free i
bindee :: String -> Expr -> Expr
bindee p (Free p') | p == p' = I
bindee p (f :$ g) = S :$ bindee p f :$ bindee p g
bindee _ e = K :$ e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment