Simply Typed λ -Calculus Akim Demaille akim@lrde.epita.fr EPITA — École Pour l’Informatique et les Techniques Avancées June 10, 2016
About these lecture notes Many of these slides are largely inspired from Andrew D. Ker’s lecture notes [Ker, 2005a, Ker, 2005b]. Some slides are even straightforward copies. A. Demaille Simply Typed λ -Calculus 2 / 46
Simply Typed λ -Calculus 1 Types λ → : Type Assignments 2 A. Demaille Simply Typed λ -Calculus 3 / 46
Types 1 Types Untyped λ -calculus Paradoxes Church vs. Curry λ → : Type Assignments 2 A. Demaille Simply Typed λ -Calculus 4 / 46
Types Alonzo Church (1903–1995) Haskell Curry (1900–1982) A. Demaille Simply Typed λ -Calculus 5 / 46
Types Types first appeared with Curry (1934) for Combinatory Logic Church (1940) Types are syntactic objects assigned to terms: M : A M has type A For instance: I : A → A A. Demaille Simply Typed λ -Calculus 6 / 46
Types Types first appeared with Curry (1934) for Combinatory Logic Church (1940) Types are syntactic objects assigned to terms: M : A M has type A For instance: I : A → A A. Demaille Simply Typed λ -Calculus 6 / 46
Untyped λ -calculus 1 Types Untyped λ -calculus Paradoxes Church vs. Curry λ → : Type Assignments 2 A. Demaille Simply Typed λ -Calculus 7 / 46
λ -terms Λ , set of λ -terms M ∈ Λ N ∈ Λ M ∈ Λ x ∈ V x ∈ V x ∈ Λ ( MN ) ∈ Λ ( λ x · M ) ∈ Λ A. Demaille Simply Typed λ -Calculus 8 / 46
λβ The λβ Formal System M = N M = N N = L M = M N = M M = L M = M ′ N = N ′ M = N MN = M ′ N ′ λ x · M = λ x · N ( λ x · M ) N = [ N / x ] M A. Demaille Simply Typed λ -Calculus 9 / 46
Properties of λβ β -reduction is Church-Rosser. Any term has (at most) a unique NF. β -reduction is not normalizing. Some terms have no NF ( Ω ). A. Demaille Simply Typed λ -Calculus 10 / 46
Properties of λβ β -reduction is Church-Rosser. Any term has (at most) a unique NF. β -reduction is not normalizing. Some terms have no NF ( Ω ). A. Demaille Simply Typed λ -Calculus 10 / 46
Properties of λβ β -reduction is Church-Rosser. Any term has (at most) a unique NF. β -reduction is not normalizing. Some terms have no NF ( Ω ). A. Demaille Simply Typed λ -Calculus 10 / 46
Properties of λβ β -reduction is Church-Rosser. Any term has (at most) a unique NF. β -reduction is not normalizing. Some terms have no NF ( Ω ). A. Demaille Simply Typed λ -Calculus 10 / 46
Paradoxes 1 Types Untyped λ -calculus Paradoxes Church vs. Curry λ → : Type Assignments 2 A. Demaille Simply Typed λ -Calculus 11 / 46
Self application What is the computational meaning of λ x · xx ? Stop considering anything can be applied to anything A function and its argument have different behaviors A. Demaille Simply Typed λ -Calculus 12 / 46
Self application What is the computational meaning of λ x · xx ? Stop considering anything can be applied to anything A function and its argument have different behaviors A. Demaille Simply Typed λ -Calculus 12 / 46
Church vs. Curry 1 Types Untyped λ -calculus Paradoxes Church vs. Curry λ → : Type Assignments 2 A. Demaille Simply Typed λ -Calculus 13 / 46
Simple Types A set of type variables α, β, . . . A symbol → for functions α → α , α → ( β → γ ) , ( α → β ) → γ , . . . Possibly constants for “primitive” types ι for integers, etc. A. Demaille Simply Typed λ -Calculus 14 / 46
Simple Types A set of type variables α, β, . . . A symbol → for functions α → α , α → ( β → γ ) , ( α → β ) → γ , . . . Possibly constants for “primitive” types ι for integers, etc. A. Demaille Simply Typed λ -Calculus 14 / 46
Simple Types A set of type variables α, β, . . . A symbol → for functions α → α , α → ( β → γ ) , ( α → β ) → γ , . . . Possibly constants for “primitive” types ι for integers, etc. A. Demaille Simply Typed λ -Calculus 14 / 46
Simple Types By convention → is right-associative: α → β → γ = α → ( β → γ ) This matches the right-associativity of λ : λ x · λ y · M = λ x · ( λ y · M ) A. Demaille Simply Typed λ -Calculus 15 / 46
Simple Types By convention → is right-associative: α → β → γ = α → ( β → γ ) This matches the right-associativity of λ : λ x · λ y · M = λ x · ( λ y · M ) A. Demaille Simply Typed λ -Calculus 15 / 46
Alonzo Style, or Haskell Way? Church: Curry: Typed λ -calculus λ -calculus with Types x : α x : α λ x α · x : α → α λ x · x : α → α A. Demaille Simply Typed λ -Calculus 16 / 46
λ → : Type Assignments Types 1 2 λ → : Type Assignments Types Type Deductions Subject Reduction Theorem Reducibility Typability A. Demaille Simply Typed λ -Calculus 17 / 46
Types Types 1 2 λ → : Type Assignments Types Type Deductions Subject Reduction Theorem Reducibility Typability A. Demaille Simply Typed λ -Calculus 18 / 46
Simple Types T V a set of type variables α, β, . . . Simple Types The set T of types σ, τ, . . . : σ ∈ T τ ∈ T α ∈ T V α ∈ T ( σ → τ ) ∈ T A. Demaille Simply Typed λ -Calculus 19 / 46
Type Contexts Statement A statement M : σ is a pair with M ∈ Λ , σ ∈ T . M is the subject, σ the predicate. Type Context, Basis A type context Γ is a finite set of statements over distinct variables { x 1 : σ 1 , . . . } . Assignment The variable x is assigned the type σ in Γ iff x : σ ∈ Γ . A. Demaille Simply Typed λ -Calculus 20 / 46
Type Contexts Statement A statement M : σ is a pair with M ∈ Λ , σ ∈ T . M is the subject, σ the predicate. Type Context, Basis A type context Γ is a finite set of statements over distinct variables { x 1 : σ 1 , . . . } . Assignment The variable x is assigned the type σ in Γ iff x : σ ∈ Γ . A. Demaille Simply Typed λ -Calculus 20 / 46
Type Contexts Statement A statement M : σ is a pair with M ∈ Λ , σ ∈ T . M is the subject, σ the predicate. Type Context, Basis A type context Γ is a finite set of statements over distinct variables { x 1 : σ 1 , . . . } . Assignment The variable x is assigned the type σ in Γ iff x : σ ∈ Γ . A. Demaille Simply Typed λ -Calculus 20 / 46
Type Contexts Type Context Restrictions Γ − x is the Γ with all assignment x : σ removed. Γ ↾ M is Γ − FV ( M ) . A. Demaille Simply Typed λ -Calculus 21 / 46
Type Deductions Types 1 2 λ → : Type Assignments Types Type Deductions Subject Reduction Theorem Reducibility Typability A. Demaille Simply Typed λ -Calculus 22 / 46
A Natural Presentation Type derivations are trees built from the following nodes. M : σ → τ N : σ A. Demaille Simply Typed λ -Calculus 23 / 46
A Natural Presentation Type derivations are trees built from the following nodes. M : σ → τ N : σ MN : τ A. Demaille Simply Typed λ -Calculus 23 / 46
A Natural Presentation Type derivations are trees built from the following nodes. x : σ · M : σ → τ N : σ · · M : τ MN : τ A. Demaille Simply Typed λ -Calculus 23 / 46
A Natural Presentation Type derivations are trees built from the following nodes. [ x : σ ] · M : σ → τ N : σ · · M : τ MN : τ λ x · M : σ → τ A. Demaille Simply Typed λ -Calculus 23 / 46
Type Statement Type Statement A statement M : σ is derivable from the type context Γ , Γ ⊢ M : σ if there is a derivation of M : σ whose non-canceled assumptions are in Γ . A. Demaille Simply Typed λ -Calculus 24 / 46
Type Statements Prove ⊢ λ fx · f ( fx ) : ( σ → σ ) → σ → σ A. Demaille Simply Typed λ -Calculus 25 / 46
Type Statements Prove ⊢ λ fx · f ( fx ) : ( σ → σ ) → σ → σ λ fx · f ( fx ) : ( σ → σ ) → σ → σ A. Demaille Simply Typed λ -Calculus 25 / 46
Type Statements Prove ⊢ λ fx · f ( fx ) : ( σ → σ ) → σ → σ [ f : σ → σ ] ( 2 ) [ x : σ ] ( 1 ) [ f : σ → σ ] ( 2 ) fx : σ f ( fx ) : σ ( 1 ) λ x · f ( fx ) : σ → σ ( 2 ) λ fx · f ( fx ) : ( σ → σ ) → σ → σ A. Demaille Simply Typed λ -Calculus 25 / 46
Type Statements Prove ⊢ λ xy · x : σ → τ → σ A. Demaille Simply Typed λ -Calculus 26 / 46
Type Statements Prove ⊢ λ xy · x : σ → τ → σ λ xy · x : σ → τ → σ A. Demaille Simply Typed λ -Calculus 26 / 46
Type Statements Prove ⊢ λ xy · x : σ → τ → σ [ x : σ ] ( 1 ) λ y · x : τ → σ ( 1 ) λ xy · x : σ → τ → σ A. Demaille Simply Typed λ -Calculus 26 / 46
Alternative Presentation of Type Derivations Type Derivations { x : σ } �→ x : σ Γ �→ M : σ → τ ∆ �→ N : σ Γ , ∆ consistent Γ ∪ ∆ �→ MN : τ Γ �→ M : τ Γ , { x : σ } consistent Γ \ { x : σ } �→ λ x · M : σ → τ Γ �→ M : τ Γ , ∆ ⊢ M : τ A. Demaille Simply Typed λ -Calculus 27 / 46
Recommend
More recommend