Problem Set 7
Home Up Problem Set 1 Problem Set 2 Problem Set 3 Problem Set 4 Problem Set 5 Problem Set 6 Problem Set 7 Problem Set 8 Problem Set 9 Problem Set 10 Final Project

 

Due 5PM Friday, October 29.

Chapter 14:

  1. Exercise 14.2 in SOE, but, as before, only for the 2nd fold law in Table 11.1,
    and the third take/drop law in Table 11.2.  If the property does not hold for infinite lists, state so, and why.
     
  2. Exercise 14.3 in SOE.
     
  3. Exercise 14.5 in SOE.

Chapter 16:

  1. A mutable variable, or reference, in Haskell might have the following interface:
     
    newRef :: a -> IO (Ref a)
    setRef :: Ref a -> a -> IO ()
    getRef :: Ref a -> IO a
     
    For example, here's a program that creates a reference with an initial value of 42, then adds it to itself, finally printing out the final value:
     
    do r <- newRef 42
       v <- getRef r
       setRef r (v+v)
       v' <- getRef r
       print v'
     
    Define these three functions using first-class channels in Haskell.  You should use good abstraction techniques to make the implementation completely opaque to the user.


Solutions.