Created
May 26, 2012 12:47
-
-
Save fumieval/2793825 to your computer and use it in GitHub Desktop.
The essence of Lazy Z compiler
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
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