Question 1: Types and Functions

with value [1, 2, 1, 2, …] which is infinitely long. (i) Write a definition of onetwo. (ii) Give the value of (take 5 (map (3*) onetwo)), and explain how it can be evaluated even though onetwo is an infinite list.

Answer: (i)

onetwo :: [Int]
onetwo = 1 : 2 : onetwo

(ii) [3, 6, 3, 6, 3] This is possible because of lazy evaluation. Onetwo requires only two cells to represent, with a circular pointer. The map defines an infinite list, but only the part that is needed is computed, and take needs only 5 elements. [Requires understanding lazy evaluation.]

Question 2: Domain Specific Languages and Parsec

Question 3: Monads and IO

Question 4: Imperative Style in Haskell