CS 334
Programming Languages
Spring 2002

Assignment 6
Due Thursday, 4/11/2002


  1. Do problem 8.18 on page 8-34. Note that each successive function is nested inside the previous. I.e., env contains a, which contains b, which contains c. Also env calls a, which calls b, which calls c, which then calls b again.

  2. Do problem 8.24 on page 8-36.

  3. Do problem 9.20 on page 9-39.

  4. As hinted in class, the THUNK's used to support recursion can also provide direct support for call-by-name parameter passing. Please modify the environment-based interpreter to use THUNK's to support call-by-name rather than call-by-value parameter passing. If you don't like your own, you can use mine, which can be found in the solutions to Assignment 4.

    When you evaluate a function call (with a user-defined function), you should not evaluate the parameter, instead package the (unevaluated) actual parameter and the current environment into a Thunk and insert it into the environment in the same way that you used to insert the value of the actual parameter into the environment. Make sure that the THUNK is handled properly when its value is needed.

  5. Recall the signature EQ and functor PairEQ from Lecture 15. Please write a functor ListEQ that takes a structure P:EQ and constructs another structure matching signature EQ such that the elements of type t are lists of elements from type P.t, and two elements are equal if they are the same length and corresponding elements are equal according to P.eq.

    Test your functor by applying it to structure IntEQ from lecture 15 to construct a structure named ListIntEQ. Show that that ListIntEQ works properly by building elements of type ListIntEQ and applying the function ListIntEQ.eq to the elements.