Spring 2001, CSE 428: Quiz 9.4 - 29 March 2001


Please write your Name and Student ID,at the top of the page.
By default, this quiz will be returned in Section 1 (afternoon section).

  1. [Pts 4]  Consider the following definition of the function "eliminate"
       fun elim(x, []) = []
         | elim(x, y::L) = if x = y then elim(x,L) else y::(elim(x,L));
    
    For each of the following expressions, say what is the result (including error). Remember that the two arguments of "=" must have the same type, and that it must be an equality type.

  2. [Pts 2]  Consider the following datatype representing binary trees with integer labels, and the definition of a function f on that datatype
       datatype tree = empty | node of (tree * int * tree);
     
       fun f empty = empty
         | f (node(empty,n,empty)) = empty;
         | f (node(t1,n,t2)) = node(f t1, n, f t2);
    
    Say what is the semantics of f (only one answer, please)

  3. [Pts 2]  Consider the following functions reduce and max :
        fun reduce(f, v, []) = v
          | reduce(f, v, x::L) = f(x, reduce(f,v,L));
    
        fun max [] = 0
          | max (x::L) = let y = max L in if x > y then x else y end;
    
    Say what is the result of the following expression (only one answer, please)
     
       reduce(max, 0, [[1,2],[3],[4],[5,6]]);
    

  4. [Pts 2]  Say which of the following expressions represents an anonymous function (only one answer, please. Note that reduce and max are the functions defined above)