MiniML Evaluator

Due Monday, October 13, at the start of class.

In this assignment, you will build an evaluator for MiniML, which is a subset of SML. You will start from a partial implementation that already includes a read-eval-print-loop user interface, a parser from text to abstract syntax trees (ASTs), a representation of the possible values resulting from evaluation, and various pretty-printing functions for ASTs and values. The partial implementation is available from your UW CSE account in the directory /cse/courses/csep505/03au/hw1; it also is available as a zip file for download.  There is a skeleton for the evaluator (in file eval.sml), with a few cases implemented to get you started; you need to complete the implementation of the evaluator. The current evaluator raises ImplementMe in all cases that you need to write; your finished solution should not raise ImplementMe anywhere. (In future assignments, you'll add a type checker and a type inferencer.)

The files

Here is a quick tour through the files of the MiniML implementation:

The files are implemented in SML structures (a.k.a. modules).  Local open declarations (a.k.a. imports) are used to allow the body of one structure to reference things declared in a different structure conveniently.  You don't really need to know anything about structures, local, or open for this project; just write your code inside the body of the Eval structure in eval.sml.

Tips

What to turn in

You should turn in your version of the file eval.sml. In addition, we'd like you to answer the following questions:

  1. Is it possible to support mutually recursive functions in the current syntax of the interpreter? Why or why not?
  2. Consider the following code:
    val x = 3
    fun f() = x
    val x = 4
    f()
    The result of f() is 3, not 4. Explain why.
  3. Consider the following code:
    fun f(x) = (let val x = 3 in x*x end) + x
    f(2)
    The result of f(2) is 11. In this invocation of f, the first two uses of x in the body have value 3, while the last use of x has value 2. How does the binding from x to 3 get removed from the environment in your interpreter?

How to turn in

Turn in your assignment by emailing it to andrei@cs.washington.edu. Please send the assignment as two attachments: one for eval.sml and another for a text file with the answers to the three questions above.