Answer to Question m18

Syntax error. A function call requires parentheses around the parameter. It should be tail(B), not tail B.

Type error. Both parameters of merge must be lists. Head(A) is an integer. The first call of merge in each case should be a call of cons.

Incorrect. The third case is wrong. Suppose A = [2,4,6] and B = [1,3,5]. Assume the first merge is cons. Then the third case says the answer is cons(2, merge([3,5], [2,4,6])). Assuming the recursive call works correctly, that yields [2, 2, 3, 4, 5, 6]. The correct answer is [1, 2, 3, 4, 5, 6].

Incorrect. The last case is incorrect. Again, suppose that the first 'merge' is replaced by 'cons', and consider A [2,4,6] and B = [1,3,5]. This function definition says that merge(A,B) is cons(1, merge([3,5], [1,3,5])). If the recursive call to merge gives the correct answer, that is [1,1,3,3,5,5].

Why does merge start by allocating an array of List pointers that it never uses?