Pencil and Paper
1. Consider the following datatype intended to represent terms in
the pure -calculus.
This is just the same as in the file lambda.ml from assignment 1, except that variables are represented by integers instead of strings.
(a) Assuming that datatypes are represented using Assumption 1 and the CAML
constructor convention as described
in class, draw a picture of the runtime data structure that would be built for
the -term ((
f.
x.(f x) x)(
y.y))(
z.z)
How much memory does the term occupy, assuming an integer and a pointer
each occupy a single word?
(b) Suppose the function reduce from lambda.ml were applied once to the term. How much additional memory (number of words) will be allocated for term storage in the course of execution? State any important assumptions you make and justify your answer.
Programming
2. File core.ml defines an interpreter for a subset of the core
-calculus given in class.
(a) The rules for evaluting Record and Select expressions are missing; add them. Hint: all the ML features you need are already illustrated in the existing code.
(b) Add an explicit Let binding construct to the lexp type and a rule for evaluating it.
For extra credit: add support for the Equal primop, to operate on any Labeled or Record value.