University of Toronto
Homework 2: Pure and Applied -Calculus
Add the following constants to our -calculus: cons, first, rest, isnil. first is a term that returns the first element of the list. For example, first [a b] = a. rest returns the list without the first element. For example, rest [a b] = [b]; rest [a] = [ ]. cons takes an element and a list and inserts the element in the beginning of the list. For example, cons a [b] = [a b]. Lists can be nested in each other, i.e. an element of a list can be a list. For example, cons [a] [b c] = [[a] b c]. Here, the first element is [a], a list.
The following are some of the -rules for these constants:
So, islist a = false whereas islist [a] = true. The new function is called toarec. To solve this problem, we will need the following definition: toarec(cons M N) - if M is a list, we have to process M recursively. Else just replace M by a. So, toarec [a b c [d e] ] = [a a a [a a] ].