CS 3520 Homework 9   - Due November 1

Exercise 9.1, Typing ref and setref

Start with this code. It contains a type-checker and interpreter like the one from lecture, except with ref and setref forms:Examples:A program using reference values can go wrong in two ways:
  1. Using setref on a non-reference:
  2. Putting the wrong type of value into a reference:
Note that, in the second case above, we blame the setref expression for changing the kind of value in x, not the addition expression for using a boolean.

To check programs using references, we must extend the grammar of type expressions:where (refto texp) means a reference containing a value of type texp.

Examples:

Ill-formed expressions:

However, the initial type-checker does not handle ref and setref properly. It always assigns the type int to a ref expression (never correct), and always assigns the type int to a setref expression (correct only if the subexpression types are appropriate).

Your task: Modify type-of-expression to correctly type-check ref and setref expressions. The places to modify the code are marked with FIXME! comments. Test your changes using the type-check function.

Hand in your revised hw9.scm.


Last update: Monday, October 30th, 2000
mflatt@cs.utah.edu