Key to CSE341 Section #1 Problems 1. (3, 4.5) int * real [4.5, 3.8] real list ((3, 4), 18.5) (int * int) * real [[3, 4], [7]] int list list [("hello", 3)] (string * int) list 2. int * string * real (3, "hello", 4.5) string list ["abc", "def", "gh"] int * string list (38, ["ab", "cd"]) (int * string) list [(38, "ab"), (19, "cd")] (int * string) list list [[(38, "ab")], [(19, "cd")]] (int * string list) list [(38, ["ab", "cd"]), (7, ["foo"])] 3. One possible solution appears below. fun gcd(x, y) = if y = 0 then x else gcd(y, x mod y) fun lcm(x, y) = x * y div gcd(x, y) 4. One possible solution appears below. fun grade(pct) = if pct >= 90.0 then "A" else if pct >= 80.0 then "B" else if pct >= 70.0 then "C" else if pct >= 60.0 then "D" else "F"; 5. One possible solution appears below. fun sum(lst) = if lst = [] then 0 else hd(lst) + sum(tl(lst)) To make it sum reals, change "0" to "0.0" in the "then" branch. 6. One possible solution appears below. fun toReal(lst) = if lst = [] then [] else real(hd(lst))::toReal(tl(lst)) 7. One possible solution appears below. (* helper function*) fun combine(first, last) = last ^ ", " ^ first; fun convert(lst) = if lst = [] then [] else combine(hd(lst))::convert(tl(lst)); 8. One possible solution appears below. fun switchPairs(lst) = if length(lst) <= 1 then lst else hd(tl(lst))::hd(lst)::switchPairs(tl(tl(lst)));