Assignment VII: Scheme, ML et al. Paper assignment only.

1. From text: problem 9.9, parts a and b. Write the type of expression for a matrix, and the type expressions for the function that adds two matrices and the function that computes the transpose of a matrix.

2. Consider the function Reduce, that we examined in class.

a) Write a C++ template with the same functionality.

b) Write an Ada generic function with the same capability.

It is interesting to note that Reduce is an APL primitive, that applies to all homogeneous binary functions. +/V is the sum of the elements of V, */V is the product of the elements of V, etc. In what way is the APL version more restrictive than the ML version?

3. Consider the Map function, whose ML definition is as follows:

fun map f lis = if null lis then [] else f (hd lis) :: (map f (tl lis));

Write the type expression for this function.

4. From text: problem 10.5, parts a) and b) (part c) is a slide from last lecture). Tail-recursive versions of familiar functions, using the programming trick known as an accumulator variable.