Reade 3.5 infix 5 upto; infix 5 downto; infix 5 fromto; fun n upto m = if n > m then [] else n :: (n+1 upto m); fun n downto m = if n < m then [] else n :: (n-1 downto m); fun n fromto m = if n < m then n upto m else n downto m; 3.13 val length = let fun addone a _ = a + 1 in accumulate addone 0 end; val majority = let fun boolint a true = a+1 | boolint a false = a-1 in accumulate boolint 0 end; Ullman 6.1(b) fun eval(nil,a) = 0.0 | eval(p::ps,a) = p + a * eval(ps,a); 6.2(b) Yes; x = "a", y = "b", zs = nil and w = 4.5 6.3 It doesn't! The pattern represents a two-element list of pairs; the expression is a one-element list of pairs, where the first element of the pair is also a pair. 6.6 fun alternate nil = nil | alternate (x::nil) = x::nil | alternate (x::y::xs) = y::x::(alternate xs); 6.10(b) fun delete (_,nil) = nil | delete (x,y::ys) = if x = y then ys else y::(delete (x,ys)); 10.1(b) We get the list [rev2,rev2] back. ML reports the result as: val it = [fn,fn] : ('a list -> 'a list) list. (d) We get the list [identity,rev1] back. ML reports the result as: val it = [fn,fn] : (''a list -> ''a list) list. Note that rev1's more restrictive type infects the entire result list. 10.3(b) fun f(x,y,z) = z+0; (d) fun f((a,b),y,z) = (a::y,b::z); 10.4(b) No, the first part of type (int -> real) is type of function. (d) Yes. 11.5(b) map (fn(x) => x + 1, L); 11.6(b) reduce(fn(x,y) => if x < y then x else y, L); (d) reduce(fn(x,y) => if x then true else y, L); or, more simply, reduce(fn(x,y) => x orelse y,L); 11.14 fun lreduceB (g,F,nil) = g | lreduceB (g,F,x::xs) = lreduceB(F(g,x),F,xs);