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...

• Notes
• 13

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 ( λ ) 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, ﬂoat, 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. 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 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.  #### You've reached the end of your free preview.

Want to read all 13 pages?

• Fall '19

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern  