# MCS-287 Homework 2 (Spring 2009)

## Due March 2, 2009

• Do exercise 6.2 on page 102. In each case, the given set is the type's set of values.
• Do exercise 6.4 on page 102. Note an erratum concerning this exercise: the last letter should be `Y`, not `Z`.
• Exercise 7.x1: Given this definition:
```fun mystery(a, b::bs) =
if a = b then
mystery(a, bs)
else
b::mystery(a, bs)
| mystery(a, []) = [];
```
What is the type of `mystery`? What is the value of `mystery(3,[3,2,1,2,3])`? What happens if you try `mystery(3.0,[3.0,2.0])`? Why?
• Do exercise 8.1 on page 130. Show your result by labeling each of the nine plus signs with a three letter abbreviation of its type, for example `irr` for `int*real->real`.
• Do exercise 8.5 on page 131.
• Exercise 9.x1: Show how `foldr` and `map` can be used in ML to start with the list `[4,5,6]` and produce the list `[8,8,10,10,12,12]`, in which each value has been "doubled" in two senses of the word: multiplied by two and repeated twice.
• Do exercise 10.3 on page 163. In part b, label each definition with an identifying letter. In part d, label each occurence with the corresponding definition's identifying letter. In part c, provide a description for each definition letter of the following form: "Block N, [except for some restriction]", where the optional restriction part indicates what fraction of block N is included. The restriction may include something like "except blocks K, L, M ...", but may also need to include some other form of restriction.