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)
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:
null
,
hd
, or tl
, nor selectors such as
#1
or #2
. Use patterns instead.
It may be useful to construct list patterns to match lists
with exactly or at least some number of
elements. For example,
[] rest [x] (x::rest) [x, y] (x::y::rest) [x, y, z] (x::y::z::rest)
local
or let
instead.ref
or op :=
.The necessary files are available in /course/csg262/assigns/hw0 on the CCS login machines, or in a tarball.
% sml -m sources.cmCurrently, 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.
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.
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.
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.
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.
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.
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.