Professional Documents
Culture Documents
CM0081 Automata and Formal Languages Programming Lab 2: Church Encoding
CM0081 Automata and Formal Languages Programming Lab 2: Church Encoding
1 Deadline
See the course homepage.
2 Lambda-Definable Functions
For representing the numeric-theoretic functions in the λ-calculus (see, for
example, [Barendregt and Barendsen 2000; Paulson 2000]) there are several
known encodings.
In the Church encoding, the natural numbers are represented by the
Church numerals:
c0 := λf x.x,
c1 := λf x.f x,
c2 := λf x.f (f x),
c3 := λf x.f (f (f x)),
..
.
cn := λf x.f n x, for n ∈ N.
c0 := λf x.x,
succ := λnf x.f (nf x),
cn+1 := succ cn .
1
Encoding for the arithmetic operations of addition, multiplication, ex-
ponentiation and predecessor is as follows.
where
3 Assignment (70%)
(i) Implementation (20%).
To write a Haskell program that implements the Church numerals and
the combinators in (1), using the Simpler, Easier! implementation for
the (untyped) λ-calculus by Augustsson.1
c0 :: Expr
cN :: Natural → Expr
2
(iii) Documentation (10%).
To document (in English) your source code (no Augustsson’s code).
The documentation should explain your solution.
4 Requirements (20%)
i) The programming lab may either be solved on your own, or jointly
with one other student taking the course.
• Your name.
• Operating system version used.
• stack version used.
• GHC version used.
• Versions used of the QuickCheck and quickcheck-instances lib-
raries.
2
See https://docs.haskellstack.org/en/stable/README/#quick-start-guide for
instructions.
3
5 Clean Code (10%)
Before submitting your programming lab, which includes your README.md
file, clean it up:
• Does not have long lines (at most 80 columns).
• Has an uniformly indentation (we recommend two characters).
• Has a consistent layout.
• Has type signatures for everything (included where-clauses and let-
definitions).
• Has good comments.
• Has spell-checked comments.
• Has no junk (unused code, commented code, unnecessary code).
• Has no overly complicated function definitions.
• Does not contain any repetitive code.
• Has no unnecessary spaces at the end of a line, or empty lines at the
end of a file.
6 Delivery
i) To create a private repository in GitHub. The name of the repository
must be cm0081-20212-lab2.
ii) Share the repository with your lecturer (user @asr).
iii) Do not include unnecessary files in the repository.
4
References
Barendregt, Henk and Barendsen, Erik (2000). Introduction to Lambda Cal-
culus. Revisited edition, Mar. 2000 (cit. on p. 1).
Paulson, Lawrence C. (2000). Foundations of Functional Programming. Lec-
ture notes. url: http : / / www . cl . cam . ac . uk / ~lp15/ (visited on
10/06/2020) (cit. on p. 1).