The reason Cons has been defined in this manner is that you can apply the

The reason cons has been defined in this manner is

This preview shows page 6 - 8 out of 8 pages.

The reason Cons has been defined in this manner, is that you can apply the following two functions to a list to get the head, and the tail of the list, respectively. This encoding uses what are called “Church pairs”. Every list has a head, which is the first element of the list, and a tail, which is the rest of the list. Head = ( λ‘ · ( λxy.x )) . Tail = ( λ‘ · ( λxy.y )) . For example, Head ( Cons a nil ) = Head ( λf · z a nil ) = ( λ‘ · ( λxy · x ))( λf · fa nil ) = ( λf · f a nil )( λxy · x ) = ( λxy · x ) a nil = a. Verify that Tail ( Cons a nil ) = nil . 5 Recursion and the Y combinator The λ -calculus does not have the provision of a function referring to itself. We will construct a function which will enable us to do recursion in the λ calculus. Any recursive function f can be written in the form f = gf . That is, f is a fixed point of the function g . There is a λ -term Y which finds the fixed point of any λ -term. In particular, for the function g , Y g = g ( Y g ). Thus, f = Y g is a definition of f . 6
Image of page 6

Subscribe to view the full document.

The Y combinator is ( λk · ( λx · k ( xx ))( λx · k ( xx ))). We can verify that Y g = g ( Y g ), thus proving that Y g is a fixed point of g . Y g = ( λk · ( λx · k ( xx ))( λx · k ( xx ))) g (1) = ( λx · g ( xx ))( λx · g ( xx )) (2) = g (( λx · g ( xx ))( λx · g ( xx ))) (3) = g ( Y g ) [from (2), (3)] (4) References [1] H. Barendregt and E. Barendsen. Introduction to the lambda calculus. Lecture Notes , 2000. [2] Amitabha Sanyal. Notes on lambda calculus. Lecture Notes , 2001. 7
Image of page 7
Addendum Recursion using the Y-combinator How do we do recursion in the λ -calculus? For a moment, let us consider how recursion and self-referential data structures work in a programming language. Suppose you have factorial(n) : if n==0 then 1 else n*factorial(n-1) this needs the facility for a function to be defined in terms of itself. How do we accomplish this? One way to easily handle this in a programming language is using symbol tables and multi-pass processing. In the first pass, for example, factorial is processed as a function. So an entry is made in the symbol table corresponding to the name factorial . This function calls another function (in this case, itself, but this is not significant) - in the first pass, we can insert a mark to say that the call is to is some entry in the symbol table, which we will resolve later. After the first pass, all names that the program defines will be known, so the symbol table will be complete. In another pass, we will go through all the marks we made earlier, and fill in the corresponding entries from the symbol table. Thus, names, symbol table and multi-pass processing is one way to enable recursion in a language. How will a λ -term refer to itself? It has no “name”, hence it cannot refer to itself by name. For this, we view a recursive λ -term as a fixed point of a sequence of definitions, and use the Y combinator. To see this, it is probably best to consider the following example, which is “almost” the definition of the factorial function.
Image of page 8
  • Fall '19
  • Satyadev Nandakumar

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes