Spring 2002, CSE 428: Quiz 8.2 - 4 April 2002


Please write your Name, Student ID, and Section at the top of the page. By default, this quiz will be return in section 2 (morning section). If you want to get it back in the afternoon section, please write "return in section 1" at the top.
  1. [Points 2] Which of the following best describes a trait specific to functional programming languages? Pick only one answer.
    1. They have polymorphic typing.
    2. They make extensive use of state and side-effects.
    3. They have garbage collectors.
    4. They treat functions as first-class values.
  2. [Points 3] The following code describes a function in SML.
    fun g nil = true
      | g (x::y::k) = g k;
    
    What function is computed by g?
    1. The function that takes a list and returns true if the list is an even length and false if the list is an odd length.
    2. The function takes a list and always returns true.
    3. It does not define a function since it causes a type error.
    4. The function is not defined for all lists since it does not have exhaustive patterns.
  3. [Points 2] What is the value computed for the following expression? 28
    let val x = 3
     in let val x = 5
         in x * x
        end
        + x 
    end;
    
  4. [Points 3] What happens when SML is given the following code?
    fun f 0 = 0
      | f n = f(n - 1) - 1;
    
    1. Defines a function which when applied to an integer, returns the modulo of that integer.
    2. Defines a function which when applied to a non-negative integer n, returns the negative of n.
    3. Gives a type error.
    4. Defines a function that gives a runtime error when applied to 1.