-
Notifications
You must be signed in to change notification settings - Fork 1
How to test out the lambda interpreter
LdBeth edited this page May 7, 2019
·
2 revisions
It is way more intuitive when u typing in repl with your hands.
First of all, load the project with
sml mlpolyr.cm
Now we can type and play in the REPL.
Each complete statement is closed by a semicolon ;
Let's rock!
(* Create some alias: *)
structure L = Lambda;
structure Inter = LambdaInterpreter;
(* helper *)
fun intv i = L.VALUE (L.INT i);
fun varv i = L.VALUE (L.VAR i);
(* stub label env *)
fun stub _ = raise Fail "This is a stub";
(* some invented programs
The definition of lambda representation is in lambda.sml
The definition of arithmetic operators are in oper.sml
*)
(* 1 + 12 *)
val program : L.exp = L.ARITH (Oper.PLUS, intv 1, intv 12);
Inter.eval stub program; (* val it = INTv 13 : LambdaInterpreter.value *)
(* more complex one *)
(* let fun id arg = arg in id 2 end *)
val (fname,arg1) = (LVar.new "id", LVar.new "arg");
val fid = (fname : L.lvar ,[arg1] : L.lvar list ,varv arg1,false);
val program1 = L.FIX ([fid], L.APP (Purity.Pure, varv fname, [intv 2]));
Inter.eval stub program1; (* val it = INTv 2 : LambdaInterpreter.value *)