Homework #5

Due: Thur, Nov 30, 10:59pm

How to Submit

  • Submit a single file named HW5.<your-username>.hs through TEACH.

  • Your submission must compile without errors in GHCi. Put all non-working parts of your solution in comments.

  • Please preserve the existing doctest comments in the template (the lines starting with >>> and the results underneath).

  • Read the Homework Policy! This describes what to do if you cannot solve a problem.


Template and supporting files: HW5.template.hs, DeBruijn.hs, Church.hs

Download all three files and put them in the same directory. You should only modify and submit the HW5 file.

In this assignment, you will be working with the implementation of lambda calculus defined in DeBruijn.hs, which we discussed in class. The file Church.hs uses this version of the lambda calculus to implement all of the Church encodings that we covered in class.

Due to time constraints, this assignment is a bit short. However, I encourage you to play around with the implementation and with the Church encodings more. For example, write some functions that manipulate nested tuples or nested sums, try to encode some simple recursive Haskell functions on natural numbers, and add new Church encodings for 4-tuples and 4-sums.

Part 1: Church pair update functions

In the first part of the assignment, you will define lambda calculus functions for updating each element of a Church-encoded pair.

  1. Define the value setFst, a lambda calculus function that updates the first element of a Church-encoded pair.

  2. Define the value setSnd, a lambda calculus function that updates the second element of a Church-encoded pair.

Part 2: Church encoding a Haskell program

In the second part of the assignment, you will be encoding a very small Haskell program in lambda calculus. The template defines a data type Foo and a function bar. Your task is to determine how to encode both of these in the lambda calculus.

  1. Define the function encodeFoo that converts a value of the Foo data type into a corresponding Church-encoded lambda calculus expression.

  2. Define the value barExp, a lambda calculus term that implements the bar function. How this function is implemented will depend on how you encoded the Foo data type. You can try out your function on a Foo with the helper function runBar.

Back to course home page