Created
May 15, 2012 07:25
-
-
Save fumieval/2699738 to your computer and use it in GitHub Desktop.
Abstraction elimination
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
import Control.Applicative | |
infixl 9 :$ | |
data Expr = Lambda String Expr -- Lambda term | |
| Free String -- Free variable | |
| S | K | I -- SKI combinator | |
| Expr :$ Expr -- Application | |
-- transformation which converts a lambda term to a SKI combinator | |
unabstractLambda :: String -- name of the formal parameter | |
-> Expr -- body | |
-> Expr -- transformed expression | |
unabstractLambda v (Lambda w e) = unabstractLambda v (unabstractLambda w e) | |
unabstractLambda x (Free x') | x == x' = I -- λx.x -> I | |
unabstractLambda x (f :$ g) = S :$ unabstractLambda x f :$ unabstractLambda x g -- λx.f g -> S f g | |
unabstractLambda _ y = K :$ y -- \x.y (y doesn't depend x) -> K y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment