Homework 2
Due March 8, 2018
- Do exercise 6.1 on page 102.
- Do exercise 6.2 on page 102. In each case, the given set is the type's set of values. Answer using ML's type notation.
- Do exercise 6.4 on page 102.
Exercise 7.x1: Given this definition:
What is the type offun mystery(a, b::bs) = if a = b then mystery(a, bs) else b::mystery(a, bs) | mystery(a, []) = [];
mystery
? What is the value ofmystery(3,[3,2,1,2,3])
? What happens if you trymystery(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
forint*real->real
. - Do exercise 8.5 on page 131.
- Exercise 9.x1: Show how
foldr
andmap
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. If the scope of a definition exceeds all of the blocks, then you should indicate "global scope".