Assignment 8
Due 3/19/09 9:30 a.m.
(Must be done with your group)

For this assignment you will need to have a good grasp of generics in Java.  Please use any Java book or online resource to learn about generics in Java. 
  1. [skills 14.1 and 14.2] Write a routine in Java that takes an array, the length of the array, and an element and returns the position of the element in the array.  For example, given the array with values [2,4,6,8] and element 6, the routine should return 2 (since counting from 0, 6 occurs at position 2 in the array).  Your routine should use templates to enable your routine to be reusable for different element types.  Be sure to test your code with a Java compiler before you submit it.
  2. [skill 14.3] Give a concrete example where you feel that parametric polymorphism is more suitable than inclusion polymorphism.  Give a concrete example where you feel that inclusion polymorphism is more suitable than parametric polymorphism.  Justify your answers.
  3. [skill 14.4] Write a generic "greater-than" function that (a) takes two objects as arguments, each of which has a "value" method which returns an integer; and (b) returns the argument whose "value" method returns the larger integer.  Your generic function should constrain its type argument so that types without "value" method cannot be used. 
  4. [synthesis] This question will touch on most of the concepts that we have covered so far (notable omissions ADT and generics) and thus it may be a particularly good one to use in your preparation of the midterm.  For this assignment, I will not limit the number of attempts to the PL-Detective.  Use as many as you want as long as you use the link given below.

    In this question you will design the full semantics of the MYSTERY language.  Use this link to submit programs to the PL-Detective.  As part of this question you will need to pick semantics for each dimension  provided by the PL-Detective (e.g., scoping).  The PL-Detective link given above has a link to a web page which describes all the options in detail.

    For each of your choices (e.g., scoping) you must justify your choice using arguments based on the characteristics in Section 1.3 of text.  We will grade you based on the quality of your arguments and to the extent you have thought about how language features interact (e.g., some of the choices in parameter-passing and type-passability may interact with each other).  More specifically, we will see if your arguments (i) provide good and complete justification for your choices; and (ii) demonstrate that you understand the implications of your choices (e.g., if a given combination of choices requires many things to be checked at run time, your discussion should point that out).

    You should assume that MYSTERY uses deep binding.  If you have other questions about  MYSTERY's fixed semantics (e.g., does MYSTERY use deep or shallow binding) you should figure these out by probing the system (much as you have been doing in the earlier assignments). 

    It is worth remembering that there is no single "perfect" language: if there was such a language then there would be no need for any other language.  In other words, there is no single "right" answer that I'm looking for: We are looking for evidence that you understand the concepts that we have covered so far, have thought about their interactions, and can provide good arguments to justify your choices.