Suggested Solutions to First Set of Exercises Reade: Solutions are all in the back of the book, and these appear to be correct. But note that the statement of problem 1.29(g) has a superfluous "end" keyword at the end of the line; the solution is ok. Ullman: Here are solutions missing from the back of the book. 1.2 b) The "then" clause is missing, so the expression will NOT have a value if condition is false; if-then-else is an operator, not a control-flow construct. d) DIV should be div. ML is case-sensitive. f) Should use "orelse" instead of "or". 2.2 b) The "then" and "else" clauses must have the same type, but here have types "int" and "real" respectively. d) The range of argument of "chr" is 0 to 255 inclusive. f) "chr" must take an integer as an argument. g) The condition should be boolean type, not integer. 4.1 b) 3. d) ["f","o","o"]. f) ["c","a","t"]. 4.3 b) int list list d) sting list * int list list 4.5 b) [(1,"a"),(2,"b")] d) (((1,2),["a","b"],3.0),(4.0,"Hi")) 5.1 There are other, more idiomatic, ways to write each of these functions: b) fun min3(a:int,b,c) = if a < b then if a < c then a else c else if b < c then b else c; d) fun len(L) = if L = nil then 0 else (1 + len(tl(L))); f) fun cycle(L) = tl(L) @ [hd(L)]; 5.2 b) fun cyclei(i,L) = if i = 0 then L else cyclei(i-1,cycle(L)); d) fun xi(x:real,i) = if i = 0 then 1.0 else x*(xi(x,i-1));