Graded Assignment 2 CM20256 / CM50262 Functional Programming
Graded Assignment 2 CM20256 / CM50262 Functional Programming
Graded Assignment 2 CM20256 / CM50262 Functional Programming
Graded Assignment 2
Note that this graded assignment is an individual assignment. Collaboration on this as-
signment is not permitted: you should not discuss your work with others, and the work you
submit should be your own. Failure to observe this constitutes plagiarism: see
http://www.bath.ac.uk/quality/documents/QA53.pdf.
Intuitively, the variable c represents the cons operation (which adds an item to the head of
the list) and the variable n represents the empty list, nil: note that the term for the empty
list is [ ] = λc.λn.n .
[3, 2, 1] times 1
Here the numerals 1 , 2 , 3 , . . . denote the λ -terms for the corresponding Church numerals,
and times is the term for multiplication. You may use the fact that times n m reduces to
the numeral n × m .
Part 2 (10%): The term cons appends an element to the front of a list.
cons , λx.λl.λc.λn. c x (l c n)
Show that it works by reducing cons 3 [2, 1] to [3, 2, 1] . Make sure to include every β -step,
and try to use abbreviations for readability.
head [N, . . . ] →∗β N empty [ ] →∗β true empty [N, . . . ] →∗β false
Graded Assignment 2 CM20256 / CM50262 Functional Programming
(where →∗β means reduction by any number of β -steps). The term head [ ] is an error
in most programming languages; in this lambda-calculus version, it may reduce to whatever
you like.
Part 4 (30%): The terms Lm and L0m for each natural number m are defined as follows.
(Note that n and c are variables while m stands for a number or its Church encoding.)
L00 = n
L0m = c m L0m−1 for m > 0
Part 5 (20%):
a) Give a λ -term that corresponds to the foldr function in Haskell. That is, your term
foldr should have the property that
[0, 1, 2, . . .]
You should explain why your functions work as they are supposed to. You need not give a
complete formal proof: a convincing explanation is all that is required.
Part 6 (20%): This last part consists of three technical but more open-ended questions.
Please take care to give a full answer that demonstrates your understanding of the concepts
involved.
Graded Assignment 2 CM20256 / CM50262 Functional Programming
a) For your three solutions for Part 5, (a) foldr, (b) map, and (c) the infinite list [0, 1, 2, ...] ,
explain if they can be typed, and why (not). For each, is it possible that there is a
solution in the typed lambda-calculus?
Use the concepts of confluence, weak normalization, and strong normalization to ex-
plain how many normal forms the term ten has, and if it might diverge (i.e. if it has an
infinite beta-reduction).
rnd Ni .
Explain how the presence of such an effect interacts with reduction strategies (normal
order, applicative order, and lazy evaluation) and with confluence.