CS334 Assignment 6


Assignment 6 ----------------------------- Due 4/22/97

Please do problem 19 on page 243 of the text, but do not turn it in. The answer is in the back of the text.

  1. Please do problem 15 on page 246 of the text.

  2. Please do problem 20 on page 246 of the text.

  3. As hinted in class, the THUNK's used to support recursion can also provide direct support for call-by-name parameter passing. Please modify the environment-based interpreter to use THUNK's to support call-by-name rather than call-by-value parameter passing. If you don't like your own, you can use mine, which can be found in ~kim/cs334stuff/ML/ML.interps/Envinterp.sml)

    When you evaluate a function call (with a user-defined function), you should not evaluate the parameter, instead package the (unevaluated) actual parameter and the current environment into a NameThunk and insert it into the environment in the same way that you used to insert the value of the actual parameter into the environment. Make sure that the THUNK is handled properly when its value is needed. (Hint: Depending on how you handled THUNK's before you may not need to make any changes to that part of your code.)

  4. Please read Chapters 14 and 15 of Ullman (or Chapter 3 of Harper's notes on ML). ML's structures provide for encapsulation, abstractions also provide for information hiding, signatures take the place of types for structures, while functors are parameterized structures. The following abstype definition of a generic stack was given in class.
    	abstype 'a stack = mkstack of ('a list)
    	  with exception stackUnderflow
    	    val emptyStk : 'a stack = mkstack []
     	   fun push (e:'a) (mkstack(s):'a stack) = mkstack(e::s)
     	   fun pop (mkstack([]):'a stack) = raise stackUnderflow
     	     | pop (mkstack(e::s):'a stack) = mkstack(s):'a stack
     	   fun top (mkstack([]):'a stack) = raise stackUnderflow
     	     | top (mkstack(e::s):'a stack) = e
     	   fun IsEmpty (mkstack([]):'a stack) = true
     	     | IsEmpty (mkstack(e::s):'a stack) = false
    1. Please write an equivalent abstraction definition and supply an appropriate signature for it. Please make sure that the implementation of stack is hidden to the user. (You should test the construct with your "balance" program from assn 2.)

    2. The footnote on page 60 of Harper's notes indicate that abstypes are being phased out of the language in favor of abstractions. Why do you think this is being done?

    3. Compare ML's abstractions and Ada's generic packages. How do they differ? Does either have any advantages over the other?