|
|
|
|||||||||||||||
|
|
Cpt S 355 Homework Assignment 3Assigned: November 15, 2004Due: December 6, 2004 in classThe textbook problem sets for the later chapters in the book are terrific review for the course. This assignment covers some of the most important topics discussed in the course, but the other problems are well worth your attention. You should consider each of the problems in Chapters 8-14 that touch in any way on things we have covered and try to frame for yourself the issues that are raised. If you can do this you will have a very solid understanding of these topics. Chapter 8 Problems 8.1, 8.2 and 8.3 -- these are short, straightforward questions about exceptions. The questions are asked about ML programs. The answers you turn in should address the questions as stated, but you should also think about how similar code would be expressed in Python, Java and C++. Chapter 9 Problem 9.5 -- this question addresses the implementation difference between parametric polymorphism in ML and parametric polymorhpism using C++ templates. Short answers are fine but they should reflect careful thinking about the issues. As add-ons to problem 9.5: rewrite the ML stack implementation given in the book as an ML structure. (Make sure you understand the difference between structure/struct in ML and struct in C.) This is an easy task but I want to make sure that you know what an ML structure looks like and the answer is needed for the next part of the question. This implementation is called a polymorphic structure. Now write a functor that will generate a stack structure for values of a particular type. This is called a monomorphic structure. Monomorphic structures, like classes generated from C++ templates only work for a single type. Thus they involve generating code for each type they are created for, but that code may be more efficient than polymorphic code. Here is an outline of the functor: functor Stack(S: sig type t end) = struct
...
end
Then to make a stack of integers, the functor would be used like this: structure IntStack = Stack (struct type t = int end); Chapter 12 Problem 12.1 -- objects on the stack, and review of object implementation issues. Problem 12.7 parts (a) and (b) -- You may want to do the experiment to confirm your understanding of the language. If you do, please say what compiler you used as well as stating the results you obtained. Problem 12.10 -- Use Figure 12.3 as a model for how to draw the diagrams for part (a). Note that the parenthetical remark in the third-to-last paragraph on p. 380 is not correct. I know of one class of counterexamples: (float) 1 will produce the floating point representation of the value 1, not treat the integer representation representation of 1 as a float. What would you have to do if you wanted to treat the bit pattern of an int as a float? Chapter 13 The number of questions here may seem like an undue emphasis on Java, but many of these address recurring themes of this course. Problem 13.1 (b) and (c) Problem 13.3 In addition to answering parts (a) and (b), experiment with javac to see if these restrictions on the sets of exceptions and the exception types are enforced? What error messages are generated? Problem 13.4 (a) (b) and (c) Problem 13.6 (c) - Hint: this not really a Java question at all; refer to question 1j on the midterm. Problem 13.7 (a) and (b) Chapter 14 Problem 14.1 |
||||||||||||||
| (c) 2003 Curtis Dyreson, (c) 2004 Carl H. Hauser E-mail questions or comments to Prof. Carl Hauser | ||||||||||||||||