Homework #5 Solution Sketches 1) fun fibhelp (1, a1, a2) = a1 | fibhelp (i, a1, a2) = fibhelp (i-1, a1+a2, a1); fun fib (0) = 0 | fib (n) = fibhelp (n, 1, 0); 2) fun remove (nil, i) = nil | remove (x::xs, 1) = xs | remove (x::xs, i) = x:: remove (xs, i-1); 3) exception EmptyList; fun lreduce (F, nil) = raise EmptyList | lreduce (F, [a]) = a | lreduce (F, x::y::remaining) = lreduce (F, F (x, y)::remaining); lreduce can be used to sum a list of numbers as follows: lreduce ((op +) [1,2,3]; 4) a) (* The key observation here is that 1-2+3-4 can be written as: 1-(2-(3-4))) With this observation, we can write the desired function as: *) val asum = foldr (op -) 0; b) fun xor2 (0, 0) = 0 | xor2 (0, 1) = 1 | xor2 (1, 0) = 1 | xor2 (1, 1) = 0; fun xor (list) = foldr xor2 0 list;