lec11.pdf - lec11 Simply Typed Lambda Calculus CS3100 Fall 2019 Review Previously Lambda calculus encodings Booleans Arithmetic Pairs Recursion Lists

lec11.pdf - lec11 Simply Typed Lambda Calculus CS3100 Fall...

This preview shows page 1 - 5 out of 13 pages.

31/08/2019 lec11 127.0.0.1:8888/notebooks/lec11/lec11.ipynb 1/13 Simply Typed Lambda Calculus CS3100 Fall 2019 Review Previously Lambda calculus encodings Booleans, Arithmetic, Pairs, Recursion, Lists Today Simply Typed Lambda Calculus Need for typing Consider the untyped lambda calculus false = λ x. λ y.y 0 = λ x. λ y.y Since everything is encoded as a function... We can easily misuse terms… false 0 λy.y if 0 then ... …because everything evaluates to some function The same thing happens in assembly language Everything is a machine word (a bunch of bits) All operations take machine words to machine words How to fix these errors? Typed Lambda Calculus Lambda Calculus + Types Simply Typed Lambda Calculus ( λ )
Image of page 1
31/08/2019 lec11 127.0.0.1:8888/notebooks/lec11/lec11.ipynb 2/13 Simple Types A , B B (base type) A B (functions) A × B (products) 1 (unit) B is base types like int, bool, float, string, etc. × binds stronger than A × B C is ( A × B ) → C is right associative. A B C is A → ( B C ) Same as OCaml If we include neither base types nor 1 , the system is degenerate. Why? Degenerate = No inhabitant. Raw Terms M , N x (variable) M N (application) λx : A . M (abstraction) M , N (pair) fst M (project-1) snd M (project-2) ( ) (unit) Typing Judgements M : A means that the term M has type A . Typing rules are expressed in terms of typing judgements . An expression of form x 1 : A 1 , x 2 : A 2 , …, x n : A n M : A Under the assumption x 1 : A 1 , x 2 : A 2 , …, x n : A n , M has type A . Assumptions are usually types for free variables in M . Use Γ for assumptions. Γ M : A Assume no repetitions in assumptions. alpha-convert to remove duplicate names.
Image of page 2
31/08/2019 lec11 127.0.0.1:8888/notebooks/lec11/lec11.ipynb 3/13 Quiz Given Γ, x : A , y : B M : C , which of the following is true? 1. M : C holds 2. x Γ 3. y Γ 4. A and B may be the same type 5. x and y may be the same variable Quiz Given Γ, x : A , y : B M : C Which of the following is true? 1. M : C holds ( M may not be a closed term) 2. x Γ ( Γ has no duplicates) 3. y Γ ( Γ has no duplicates) 4. A and B may be the same type ( A and B are type variables) 5. x and y may be the same variable ( Γ has no duplicates) Typing rules for λ Γ, x : A x : A ( var ) Γ ( ): 1 ( unit ) Γ M : A B Γ N : A Γ M N : B ( → elim ) Γ, x : A M : B Γ λx : A . M : A B ( → intro ) Γ M : A × B Γ fst M : A ( × elim 1) Γ M : A × B Γ snd M : B ( × elim 2) Γ M : A Γ N : B Γ M , N : A × B ( × intro ) Typing derivation
Image of page 3
31/08/2019 lec11 127.0.0.1:8888/notebooks/lec11/lec11.ipynb 4/13 x : A A , y : A x : A A ( var ) x : A A , y : A x : A A ( var ) x : A A , y : A x : A A , y : A ( x y ): A x : A A , y : A x ( x y ): A x : A A ( λy : A . x ( x y )): A A ( λx : A A . λy : A . x ( x y )): ( A A ) → A Typing derivation For each lambda term, there is exactly one type rule that applies.
Image of page 4
Image of page 5

You've reached the end of your free preview.

Want to read all 13 pages?

  • Fall '19

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

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors