Problem Set 3
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

 

Changes to this assignment appear in red.

Was Due 5PM Friday, September 24.
Now due 10:30AM Monday, September 27.

Chapter 7:

  1. Exercise 7.2 in SOE.
     
  2. Define a fold function (call it foldExpr) for the Expr data type.
    Then define evaluate in terms of foldExpr.
     
  3. Exercise 7.5 in SOE, using the result of the above exercise.  You should call
    the new data type Expr2, and the new evaluator evaluate2.

    Hints: (1) You will have to create an environment that keeps track of bound
    variables.  I suggest implementing the environment as a function of type
    String -> Float. (2) Previously, the meaning of an expression had
    type Float.  I suggest now treating the meaning of an expression as a
    function
    of type Env -> Float.

Chapter 8:

  1. Exercise 8.3 in SOE.
     
  2. Exercise 8.6 in SOE.
     
  3. Exercise 8.8 in SOE.
     
  4. Exercise 8.9 in SOE, but only for the 1st, 3rd, 5th, and 10th theorems.

Chapter 9:

  1. Exercise 9.3 in SOE.
     
  2. Exercise 9.4 in SOE.
     
  3. Exercise 9.5 in SOE.
     
  4. Exercise 9.7 in SOE.
     
  5. Exercise  9.9 in SOE.

    Hint: A fixpoint of a function f is a value x such that f x = x.  Interestingly, fix computes a fixpoint of a function, because fix f is defined as f (fix f) -- so by definition it is a fixpoint!!

    Now consider the recursive equation ones = 1 : ones.  What value of ones satisfies this equation?  The answer is the infinite list of ones.  But note that this is the same as asking what is the fixpoint of \ones -> 1 : ones, because this function, when applied to its fixpoint, must equal the same value.  That is:

    (\ones -> 1 : ones) ones = 1 : ones = ones

    Indeed, fix (\ones -> 1 : ones) is the answer we want.  To convince yourself of this, try evaluating this in Hugs:

    take 10 (fix (\ones -> 1 : ones))

    So to solve the original problem, think of the equation for remainder to be like the equation for ones above.

     
  6. Exercise 9.10 in SOE.

 

Solutions.