f593f4d7bdc89d9af36ac1a68f1336c0880ed9b8
[lambda.git] / exercises / assignment3.mdwn
1 ## Comprehensions
2
3 3. Using either Kapulet's or Haskell's list comprehension syntax, write an expression that transforms `[3, 1, 0, 2]` into `[3, 3, 3, 1, 2, 2]`.
4
5 *Here is a hint*
6
7 Define a function `dup (n, x)` that creates a list of *n* copies of `x`. Then use list comprehensions to transform `[3, 1, 0, 2]` into `[[3, 3, 3], [1], [], [2, 2]]`. Then use `join` to "flatten" the result.
8
9
10
11 ## Lists
12
13 7. Continuing to encode lists in terms of their left-folds, how should we write `head`? This is challenging.
14
15 *Here is a hint*
16
17