Description
1. [Lists] Write a Haskell function TakeAlternate which takes two argu-
ments. The #rst argument is a natural number N and the second is a
list of type [a] . It should return a list of N elements from the positions
0 , 2 , . . . , 2N if the list is su#ciently long.
In cases where the list is too short, it should return as many elements
as it can. [10]
2. [Lists] Write a Haskell function Last which takes a list of type [a] and
returns the last element.
Handle empty lists correctly. [10]
3. [Lists] Write a Haskell function Merge of type [a] → [a] → [a] which
merges two sorted lists and produces a merged sorted list with no
duplicates. (all in the same ordering) [10]
4. a. [Lists] Write a Haskell function Zip of type [a] → [b] → [(a, b)]
which takes two lists of equal length and produces a list of tuples – the
#rst element from each tuple comes from the #rst list, and the second
comes from the second list. The output obeys the input ordering. [10]
b. [Higher Order Programming] Write a Haskell function ZipWith of
type (a → b → c) → [a] → [b] → [c] which takes a function f of type
(a → b → c) , and two lists [x 1 , x 2 , . . . ] and [y 1 , y 2 , . . . ] and produces
the list [(f x 1 y 1 ), (f x 2 y 2 ), . . . ] . [10]
5. [Higher Order Programming] Write a right-associative fold, called foldR .
[10]
Implement map using foldR . [10]
16. Produce an in#nite stream of numbers which are multiples of 2, 3 or
5, in strictly ascending order,
a. using list comprehension [10]
b. using self-referential streams [15]