Term ::= Var| \Var.Term | Term Term % lambda terms
| Num | true | false % numerical and boolean constants
| Term Op Term % numerical ops and comparison
| cons(Term,Term) % stream constructor
| head Term | tail Term % stream selectors
| if Term then Term else Term % conditional
| let Var = Term in Term % term with a local declaration
| fix Term % the fixpoint operator
The interpreter should be environment-based (see Lecture Notes 16 and 17),
and treat the scope correctly, i.e. it should have static scope.
Furthermore, please define a term Test_lazy representing the PCF term
\x y z. if x then y else z
Finally, please define a term Test_static representing the PCF term
\s. let n = 1
in let s1 = cons(0,cons(n,s))
in let n = 2
in s1
Please use ML val declaration to give these definitions, i.e.
val Primes = < ML expression of type term, representing the sieve of Eratosthenes > val Test_lazy = < ML expression of type term, representing \x y z. if x then y else z > val Test_static = < ML expression of type term, representing \s. let n = 1 ... >These definitions will be tested by us in contexts of the form
eval head(tail(tail(...(tail(Primes))...))) emptyenv
eval (app(app(app(Test_lazy,M),N),P)) emptyenv
eval (head(tail(...(app(Test_static,S))...) emptyenv
(* (head(tail(app(Test_static,S)))) should give 1 *)
Please submit a hard-copy of the code by the deadline, as usual. In addition, please submit the electronic version (for testing purposes) by sending an email to cg520@cse.psu.edu by the deadline.
I will be busy teaching two other classes on MWF in the last three weeks of November. Hence, it's unlikely that you find me in my office without appointment. Please try to come during the office hours. If you can't come during office hours, please send email for appoinment, or (better) send your questions by email.
Well, that's all... I hope you will have fun with this interpreter! Good luck, -Catuscia