chapter 9: simply typed lambda-calculus · chapter 9: simply typed lambda-calculus function types...
TRANSCRIPT
![Page 1: Chapter 9: Simply Typed Lambda-Calculus · Chapter 9: Simply Typed Lambda-Calculus Function Types The Typing Relation Properties of Typing The Curry-Howard Correspondence Erasure](https://reader035.vdocuments.site/reader035/viewer/2022063017/5fd84c18d8a5ee02cd55deac/html5/thumbnails/1.jpg)
Chapter 9: Simply Typed Lambda-Calculus
Function Types
The Typing Relation
Properties of Typing
The Curry-Howard Correspondence
Erasure and Typability
![Page 2: Chapter 9: Simply Typed Lambda-Calculus · Chapter 9: Simply Typed Lambda-Calculus Function Types The Typing Relation Properties of Typing The Curry-Howard Correspondence Erasure](https://reader035.vdocuments.site/reader035/viewer/2022063017/5fd84c18d8a5ee02cd55deac/html5/thumbnails/2.jpg)
Function Types
• T1→T2 – classifying functions that expect arguments of type T1 and
return results of type T2.
(The type constructor → is right-associative.
T1→T2→T3 stands for T1→(T2→T3) )
• We will consider Booleans with lambda calculus– T ::= Bool
T T
• Examples– Bool→Bool
– (Bool→Bool) → (Bool→Bool)
![Page 3: Chapter 9: Simply Typed Lambda-Calculus · Chapter 9: Simply Typed Lambda-Calculus Function Types The Typing Relation Properties of Typing The Curry-Howard Correspondence Erasure](https://reader035.vdocuments.site/reader035/viewer/2022063017/5fd84c18d8a5ee02cd55deac/html5/thumbnails/3.jpg)
λ
Assume all variables in Γare differentRenaming if some are not
![Page 4: Chapter 9: Simply Typed Lambda-Calculus · Chapter 9: Simply Typed Lambda-Calculus Function Types The Typing Relation Properties of Typing The Curry-Howard Correspondence Erasure](https://reader035.vdocuments.site/reader035/viewer/2022063017/5fd84c18d8a5ee02cd55deac/html5/thumbnails/4.jpg)
Type Derivation Tree
![Page 5: Chapter 9: Simply Typed Lambda-Calculus · Chapter 9: Simply Typed Lambda-Calculus Function Types The Typing Relation Properties of Typing The Curry-Howard Correspondence Erasure](https://reader035.vdocuments.site/reader035/viewer/2022063017/5fd84c18d8a5ee02cd55deac/html5/thumbnails/5.jpg)
Properties of Typing
Inversion Lemma
Uniqueness of Types
Canonical Forms
Safety: Progress + Preservation
![Page 6: Chapter 9: Simply Typed Lambda-Calculus · Chapter 9: Simply Typed Lambda-Calculus Function Types The Typing Relation Properties of Typing The Curry-Howard Correspondence Erasure](https://reader035.vdocuments.site/reader035/viewer/2022063017/5fd84c18d8a5ee02cd55deac/html5/thumbnails/6.jpg)
Inversion Lemma
Exercise: Is there any context Γ and type T such that Γ ⊢ x x:T?
![Page 7: Chapter 9: Simply Typed Lambda-Calculus · Chapter 9: Simply Typed Lambda-Calculus Function Types The Typing Relation Properties of Typing The Curry-Howard Correspondence Erasure](https://reader035.vdocuments.site/reader035/viewer/2022063017/5fd84c18d8a5ee02cd55deac/html5/thumbnails/7.jpg)
Uniqueness of Types
• Theorem [Uniqueness of Types]: In a given typing context Γ, a term t (with free variables all in the domain of Γ) has at most one type. Moreover, there is just one derivation of this typing built from the inference rules that generate the typing relation.
![Page 8: Chapter 9: Simply Typed Lambda-Calculus · Chapter 9: Simply Typed Lambda-Calculus Function Types The Typing Relation Properties of Typing The Curry-Howard Correspondence Erasure](https://reader035.vdocuments.site/reader035/viewer/2022063017/5fd84c18d8a5ee02cd55deac/html5/thumbnails/8.jpg)
Canonical Form
• Lemma [Canonical Forms]: – If v is a value of type Bool, then v is either true or false.
– If v is a value of type T1→T2, then v = λx:T1.t2.
![Page 9: Chapter 9: Simply Typed Lambda-Calculus · Chapter 9: Simply Typed Lambda-Calculus Function Types The Typing Relation Properties of Typing The Curry-Howard Correspondence Erasure](https://reader035.vdocuments.site/reader035/viewer/2022063017/5fd84c18d8a5ee02cd55deac/html5/thumbnails/9.jpg)
Progress
• Theorem [Progress]: Suppose t is a closed, well-typed term. Then either t is a value or else there is some t′ with t → t′.
Proof: By induction on typing derivations.
Closed: No free variableWell-typed: ⊢ t : T for some T
![Page 10: Chapter 9: Simply Typed Lambda-Calculus · Chapter 9: Simply Typed Lambda-Calculus Function Types The Typing Relation Properties of Typing The Curry-Howard Correspondence Erasure](https://reader035.vdocuments.site/reader035/viewer/2022063017/5fd84c18d8a5ee02cd55deac/html5/thumbnails/10.jpg)
Two Structural Lemmas
• Lemma [Permutation]: If Γ ⊢ t : T and ∆ is a permutation of Γ, then ∆ ⊢ t : T.
• Lemma [Weakening]: If Γ⊢ t:T and x is not in dom(Γ), then Γ, x:S ⊢ t:T.
Note: All can be easily proved by induction on derivation
![Page 11: Chapter 9: Simply Typed Lambda-Calculus · Chapter 9: Simply Typed Lambda-Calculus Function Types The Typing Relation Properties of Typing The Curry-Howard Correspondence Erasure](https://reader035.vdocuments.site/reader035/viewer/2022063017/5fd84c18d8a5ee02cd55deac/html5/thumbnails/11.jpg)
Preservation
• Lemma [Preservation of types under substitution]: If Γ, x:S ⊢ t:T and Γ⊢s:S,
then Γ⊢[xs]t:T.
Proof: By induction on derivation of Γ, x:S ⊢ t : T.
• Theorem [Preservation]:
If Γ⊢t:T and t →t′, then Γ ⊢t′ :T.
![Page 12: Chapter 9: Simply Typed Lambda-Calculus · Chapter 9: Simply Typed Lambda-Calculus Function Types The Typing Relation Properties of Typing The Curry-Howard Correspondence Erasure](https://reader035.vdocuments.site/reader035/viewer/2022063017/5fd84c18d8a5ee02cd55deac/html5/thumbnails/12.jpg)
The Curry-Howard Correspondence
• A connection between logic and type theory
![Page 13: Chapter 9: Simply Typed Lambda-Calculus · Chapter 9: Simply Typed Lambda-Calculus Function Types The Typing Relation Properties of Typing The Curry-Howard Correspondence Erasure](https://reader035.vdocuments.site/reader035/viewer/2022063017/5fd84c18d8a5ee02cd55deac/html5/thumbnails/13.jpg)
Erasure and Typability
• Types are used during type checking, but do not appear in the compiled form of the program.
Untyped?
![Page 14: Chapter 9: Simply Typed Lambda-Calculus · Chapter 9: Simply Typed Lambda-Calculus Function Types The Typing Relation Properties of Typing The Curry-Howard Correspondence Erasure](https://reader035.vdocuments.site/reader035/viewer/2022063017/5fd84c18d8a5ee02cd55deac/html5/thumbnails/14.jpg)
Curry-Style vs. Church-Style
• Curry Style
– Syntax Semantics Typing
– Semantics is defined on untyped terms
– Often used for implicit typed languages
• Church Style– Syntax Typing Semantics
– Sematnics is defined only on well-typed terms
– Often used for explicit typed languages
![Page 15: Chapter 9: Simply Typed Lambda-Calculus · Chapter 9: Simply Typed Lambda-Calculus Function Types The Typing Relation Properties of Typing The Curry-Howard Correspondence Erasure](https://reader035.vdocuments.site/reader035/viewer/2022063017/5fd84c18d8a5ee02cd55deac/html5/thumbnails/15.jpg)
Homework
• Read Chapter 9.
• Do Exercise 9.3.9.