Implementation in ML
datatype exp = Var of string
| Abs of string * exp
| App of exp * exp
กฤ
fun PE (Var(x)) = Var(x)
| PE (Abs(x, e)) =
let val y = gensym ()
in Abs(y, PE (subst x (Var(y)) e))
end
| PE (App(e1, e2)) =
let val e1' = PE e1
val e2' = PE e2
in (case e1' of
Abs(x, e) => PE (subst x e2' e)
| e => App(e, e2'))
end
Previous slide
Next slide
Back to first slide
View graphic version