Assignment 6, Order of evaluation and subtyping
Due 3/02/04 9:30 a.m.
(Must be done with your group)

  1. Give and explain an example that shows that ARRAY I OF T <: ARRAY I OF U, if T <: U is an incorrect subtyping rule for updatable arrays.
  2. Should a boolean type be a subtype of an integer type?  Defend your case.
  3. In this question we will discusses the issues with short-circuit evaluation.
    1. Give an example that illustrates the usefulness of short circuit evaluation.  Explain your example.
    2. Discover and indicate whether or not mystery uses short-circuit evaluation of boolean operators (i.e., AND).  Use this link to submit programs.  You should provide evidence that supports your argument.  Your program should not execute PRINT more than three times.  You will lose 5% of the points for this question for each additional executed PRINT. 
  4. Even though Java's narrowing conversions for primitives may fail (e.g., cause an overflow), they never result in a run-time exception (i.e., the program continues as if nothing bad happened).  An alternative to this is to stop program execution and report a problem.  Discuss the relative merits of the two alternatives.  You may want to read the section on "narrowing primitive conversions" and "widening primitive conversions" in the Java language definition before answering this question.
  5. How does the guarded command differ from an IF statement in C++?  Give and discuss an example that illustrates the difference between the two.
  6. Consider two procedure types in MYSTERY syntax
    TYPE P1 = PROCEDURE (A1 a):R1, and
    TYPE P2 = PROCEDURE (A2 a):R2 

    There are three possible requirements for P1 <: P2

    1. A1 = A2 and R1 = R2
    2. Arguments follow the argument part of the arrow rule and R1 = R2
    3. A1 = A2 and return types follows the return type part of the arrow rule
    Answer the following questions:
    1. Discuss which of the above three possibilities you prefer.  Provide clear examples and arguments to support your preference.
    2. Assuming that MYSTERY allows subtypes to be assigned to supertypes, uses structural equality, and uses the obvious subtyping between subranges (e.g., [1 TO 10] <: [1 TO 100]) determine which of the above three possibilities is used by MYSTERY.  Use this link to submit programs.  You may submit up to six programs;  you will lose 5% of the points for each additional submission.  Provide evidence that supports your answer.