CS330 Spring 2004 Lecture 11

George Tzanetakis

Slides 

This lecture will not contain any slides as it consists mainly of
programming examples in sml.

SML code

Code in text format
 

Suggested exercises

(* This exercise is difficult but if you do it you will
understand a lot about the SML module system,
be able to solve assignment 3 easily and
and most likely get an A+ in this class so it's worth
working on it  *)

11) Define a signature ARITH for types that support
addition/subtraction/multiplication/division. Write structures IntArith,
RationalArith and ComplexArith that match this signature.
Write a signature for expression trees of integers (define
a datatype for integer expressions with datatype constructors
PLUS of int * int | PROD of int * int etc.  Write a function
eval to compute the result of an integer expression tree.

Write a functor that takes as input a structure with signature ARITH
and returns a structure that corresponds to expression trees with items
of that particular structure with signature ARITH. Using the functor
generate structure for Rational Number Expressions, Complex Number Expressions
and Integer Expressions.