playground/sml/phoas.sml
2023-04-08 14:19:57 +05:30

19 lines
334 B
Standard ML

datatype 'v tm
= Var of 'v
| App of 'v tm * 'v tm
| Abs of 'v -> 'v tm
val a = Abs (fn x=>App (Var x, Var x))
val b = App (a, a)
(* numVars : () tm -> int *)
fun numVars t =
case t of
Var v => 1
| App (t1, t2) => (numVars t1) + (numVars t2)
| Abs f => numVars (f ())
(* - numVars b; *)
(* val it = 4 : int *)