Skip to topic | Skip to bottom


POPL.Assignment4r1.2 - 11 Nov 2009 - 09:29 - EelcoVisser

Start of topic | Skip to actions

Assignment 4: Laziness

This is a written assignment.

Problem 1

In our lazy interpreter, we identified three points in the language where we need to force evaluation of expression closures (by invoking strict): the function position of an application, the test expression of a conditional, and arithmetic primitives. Doug Oord, a fairly sedentary student, is rather taken with the idea of laziness. He suggests that we can reduce the amount of code we need to write by replacing all invocations of strict with just one. In the interpreter he removes all instances of strict and replaces

[id (v) (lookup v env)] 


[id (v) (strict (lookup v env))] 

Doug’s reasoning is that the only time the interpreter returns an expression closure is on looking up an identifier in the environment. If we force its evaluation right away, we can be sure no other part of the interpreter will get an expression closure, so removing those other invocations of strict will do no harm. Being lazy himself, however, Doug fails to reason in the other direction, namely whether this will result in an overly eager interpreter.

Is it possible to write a program that will produce different results under the original interpreter and Doug’s? Let the interpreted language feature arithmetic, first-class functions, with, if0, and rec (even though these are not in our in-class lazy interpreter).

If so, hand in an example program and the result under each interpreter, and clearly identify which interpreter will produce each result. Be sure to compare this behavior against that of the lazy interpreter of the sort we have written in class rather than the behavior of Haskell! Note: it should not be difficult to construct test interpreters from your solution to the Extended Interpreter assignment and the code we give you in the textbook. You may use these to help you test your conjectures.

If it's not possible, defend why one cannot exist, and then consider the same language with cons, first, and rest added. Also, keep in mind that the REPL is always a strictness point. If you were running your lazy interpreter from DrScheme, you would type the following into the interactions pane:

> (strict (interp '{...} (mtSub)))

Problem 2 No lazy language in history has also had state operations (such as mutating the values in boxes, or assigning values to variables). Why not?

The best answer to this question would include two things: a short program (which we assume will evaluate in a lazy regime) that uses state, and a brief explanation of what problem the execution of this program illustrates. Please be sure to use the non-caching (ie, original) notion of laziness. If you present a sufficiently illustrative example (which needn’t be very long!), your explanation can be quite short.


This is an individual assignment, each student is expected to hand in their own solution. Mind the Handin Guidelines.

-- SanderVermolen - 05 Nov 2009

You are here: POPL > Schedule > Assignments > Assignment4

to top

Copyright © 2003-2018, Software Engineering Research Group, Delft University of Technology, The Netherlands