(* examples from the text *) fun repeatEach([]) = [] | repeatEach(a::rest) = a::a::repeatEach(rest); fun sum([]) = 0 | sum(a::rest) = a + sum(rest); fun switchPair([]) = [] | switchPair((a,b)::rest) = (b, a)::switchPair(rest); (* 2.2.4 -- in class*) fun count([]) = 0 | count(a::rest) = 1 + count(rest); (* 2.2.5 -- in class *) fun findIth([], i) = ~1 | findIth(a::rest, 0) = a | findIth(a::rest, i) = findIth(rest, i-1); (* 2.2.6 -- in class *) fun reverse([]) = [] | reverse(a::rest) = reverse(rest)@[a]; (* Ex 2.2.10 -- in class *) fun listify([]) = [] | listify(a::rest) = [a]::listify(rest); (* Ex 2.2.12 -- in class *) fun splitList([]) = [] | splitList((a,b)::rest) = let val (yy,zz) = splitList(rest); (a::yy, b::xx) end; (* Ex 2.2.13 -- homework *) fun tuplify([], []) = [] | tuplify(a::rest, []) = ?? | tuplify([], b::rest) = ?? | tuplify(a::aRest, b::bRest) = ?? (* Ex 2.2.14 -- in class *) fun sumPairs([]) = [] | sumPairs((a,b)::rest) = (a + b)::sumPairs(rest); (* Ex 2.2.15 -- homework *) fun sumPairList([]) = (0, 0) | sumPairList((a,b)::rest) = let val (c, d) = sumPairList(rest) in ?? end; (* For the next HW assignment (due Sept 12) *) (* Ex 2.4.14 -- homework *) (* The second parameter is a list of lists *) fun addToEach(x, []) = ?? | addToEach(x, aa::rest) = ?? (* aa is itself a list ! *) (* Ex 2.4.15 -- homework *) fun powerset([]) = ?? (* Think carefully: What is the powerset of the empty set? *) | powerset(a::rest) = ??