| | |
Summary: First name Last name Matriculation number
1
Exercise 1 (4 + 3 + 4 + 5 = 16 points)
The following data structure represents polymorphic lists that can contain values of two types
in arbitrary order:
data DuoList a b = C a (DuoList a b) | D b (DuoList a b) | E
Consider the following list zs of integers and characters:
[ 4,
a
,
b
, 6 ]
The representation of zs as an object of type DuoList Int Char in Haskell would be:
C 4 (D 'a' (D 'b' (C 6 E)))
Implement the following functions in Haskell.
(a) The function foldDuo of type
(a -> c -> c) -> (b -> c -> c) -> c -> DuoList a b -> c
works as follows: foldDuo f g h xs replaces all occurrences of the constructor C in the
list xs by f, it replaces all occurrences of the constructor D in xs by g, and it replaces all
occurrences of the constructor E in xs by h. So for the list zs above,
|