Homework 0: SML Finger Exercises

Due Tuesday, 15 January 2008, 6 PM

Correction: Early versions of sources.cm omitted a line for dictplusfn.sml. Don't forget to add it. (Sat Jan 12 16:43:22 EST 2008)

No late days permitted

Because I plan to hand out solution sets in lecture immediately after this is due, you may not use any of your late days on this assignment.


This homework assignment is intended to get you acquainted with Standard ML. To this end:

The exercises

The necessary files are available in /course/csg262/assigns/hw0 on the CCS login machines, or in a tarball.

  1. Look in the file sources.cm. This file is used by the SML/NJ Compilation Manager to tell it which files to compile or load. You can tell SML/NJ to compile and load the files in the list by running:
    % sml -m sources.cm
    Currently, the files that you need to modify are commented out, because attempting to load them before they are complete would result in errors. As you work on each file you should remember to uncomment its line in sources.cm and try your code in SML/NJ.
  2. Look at the signature WARMUP in warmup.sig. It gives names, types, and descriptions for several SML functions. Define these functions on the structure Warmup in warmup.sml. If you do this correctly, you should be able to uncomment the (* warmup.sml *) line in sources.cm and load your code into SML/NJ. Once you get it to load without type errors, you'll be able to try out the functions interactively and make sure they work.
  3. The file queue.sig contains a signature QUEUE that describes an abstract type representing functional queues with several operations. One possible representation of a queue is as a list. Implement the operations for this representation in listqueue.sml.
  4. In the representation of queues as lists, either get or put requires an O(n) traversal of the whole list. It's possible to represent functional (immutable) queues such that both operations happen in amortized O(1) time. (This means that over time, some operations may be expensive, but the worst-case cost of n successive operations is O(n).) In amortizedqueue.sml, define the type 'a queue and the associated values so that both get and put run in amortized constant time. Don't forget to uncomment the appropriate lines in sources.cm and try out your code.
  5. The file dict.sig contains a signature DICT with an abstract type 'a dict representing dictionaries (also known as environments or finite maps) mapping string keys to values of type 'a. The structures AListDict (alistdict.sml) and FunDict (fundict.sml) define two different representations for an 'a dict. Implement the rest of both structures.
  6. The file dictplusfn.sml declares a signature DICTPLUS for dictionaries with two additional operations. The functor DictPlusFn (in the same file), given a structure matching DICT, produces a structure matching DICTPLUS. Define the two missing functions in DictPlusFn. This functor should not depend on implementation details of the given DICT, so it will work with AListDict, FunDict, or any other DICT structure.

When you are finished, all the commented lines in sources.cm should be uncommented, and you should be able to load all the files with sml -m sources.cm with no type errors nor other warning messages.

How to submit

In addition to all the files mentioned above, please include an ASCII text file named README containing your name, how long you spent on this assignment, and anything else you'd like me to know.

Please submit according to the submission instructions. If you run the submission command from within the directory that you'd like to submit, then your submission command will look something like:

            % /course/csg262/bin/submit-csg262 submit 0

Last updated 18 February 2008. This homework is based on a similar set of exercises by Norman Ramsey.

Valid XHTML 1.1 Valid CSS!