CSE583 Assignment 1 (Winter 2000)
See the basic page
on assignments for program weights, rules for working in pairs, etc.
This assignment is due on Friday, February 11, 2000 at 5PM PST. We will make
an announcement later about the specific electronic form for turning in the
There is no programming for this assignment!
- (21 points) This question concerns abstract types and subtypes, parameterized types,
and the contravariant rule. We have an abstract type Consumer,
parameterized by T, the type of object that the Consumer consumes. Consumer
has a single operation eat, which takes a single argument of type T
and doesn't return anything. We also have an abstract type Producer,
again parameterized by T. Producer has a single operation make,
which takes no arguments and returns an object of type T.
Finally we have an abstract type ProducerConsumer, again
parameterized by T, the type of object that the ProducerConsumer
contains. ProducerConsumer has two operations: eat and make.
Using the contravariant rule, what is the subtype relation between the
following pairs of types? (The answer to each question would be either X
is a subtype of Y, Y is a subtype of X, or
neither is a subtype of the other.)
- ProducerConsumer[Integer] and ProducerConsumer[Number]
- Consumer[Integer] and Consumer[Number]
- Producer[Integer] and Producer[Number]
- ProducerConsumer[Integer] and Producer[Number]
- ProducerConsumer[Number] and Producer[Integer]
- ProducerConsumer[Integer] and Consumer[Number]
- ProducerConsumer[Number] and Consumer[Integer]
- (21 points) The same as the previous question, except use the covariant rule. If the
covariant rule gives an incorrect answer, sketch a program that breaks; or
one that will always execute without type errors, even though the covariant
rule says it is incorrect.
- (20 points) Give two realistic examples of object-oriented programs in which static
type checking is too restrictive. (You don't have to write out the program,
just describe the situation.)
- (14 points) Multi-methods tend to reduce the size of programs. Argue
concisely (no more than a paragraph) about whether you believe that
multi-methods tend to make those programs easier to understand and to
- (24 points) For each of the following, state whether it would be
relatively straightforward to achieve using the metaobject protocol.
Briefly justify each answer.
- Track the number of invocations of each function in the program.
- Replace a classic garbage collector for reclaiming memory with a
reference counting engine.
- Implement multi-methods.
- Change CLOS multiple inheritance from linearizing all instance
variables in the (multiple inheritance) hierarchy to another policy
(such as not permitting any conflicts in the names of instance
Department of Computer Science & Engineering|
University of Washington
Seattle, WA 98195-2350
(206) 543-1695 voice, (206) 543-2969 FAX