(* This first one does not work ! *) fun contains(x, []) = false | contains(x, x::rest) = true (* bad! *) | contains(x, y::rest) = contains(x, rest); (* Instead, use the conditional operator *) fun contains(x, []) = false | contains(x, y::rest) = if x = y then true else contains(x, rest); (* Alternately, we could do it this way... *) fun contains(x, []) = false | contains(x, y::rest) = x = y orelse contains(x, rest); (* Ex 3.7.5, hasNoRepeats (in class) *) fun hasNoRepeats([]) = true | hasNoRepeats(x::rest) = if contains(x, rest) then false else hasNoRepeats(rest); fun hasNoRepeats([]) = true | hasNoRepeats(x::rest) = not (contains(x, rest)) andalso hasNoRepeats(rest); (* Ex 3.7.6, isSubsetOf (in class) *) fun isSubsetOf([], bb) = true | isSubSetOf(a::rest, bb) = if contains(a, bb) then isSubSetOf(rest,bb) else false; (* Ex 3.7.7, intersection (HW) *) (* Order doesn't matter, but there should be no repated elements; you may assume the parameters have no repeated elements. *) fun intersection([], bb) = | intersection(a::rest, bb) = (* Ex 3.7.10, numEvens (in class) *) fun numEvens([]) = 0 | numEvens(a::rest) = if a mod 2 = 0 then 1 + numEvens(rest) else numEvens(rest); fun numEvens([]) = 0 | numEvens(a::rest) = numEvens(rest) + (if a mod 2= 0 then 1 else 0); fun numEvens([]) = 0 | numEvens(a::rest) = ((a + 1) mod 2) + numEvens(rest) ; (* Ex 3.7.11, removeFirst (in class) *) fun removeFirst(x, []) = [] | removeFirst(x, y::rest) = if x = y then rest else y::removeFirst(x, rest); (* Ex 3.7.12, listMin (HW) *) fun listMin([x])= x | listMin(x::rest) =