Advanced Semantics of Programming Languages Pierre C LAIRAMBAULT & Colin R IBA LIP - ENS de Lyon Course 13 12/11 C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 1 / 12
System F The Polymorphic Lambda-Calculus (a.k.a. System F ) C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 2 / 12
System F Introduction Example (Map). ◮ Consider a map function ( σ → τ ) × list ( σ ) − → : list ( τ ) map σ,τ ( σ, τ types) � � �− → f , [ a 0 ; . . . ; a n ] [ f ( a 0 ) ; . . . ; f ( a n )] C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 3 / 12
System F Introduction Example (Map). ◮ Consider a map function ( σ → τ ) × list ( σ ) − → : list ( τ ) map σ,τ ( σ, τ types) � � �− → f , [ a 0 ; . . . ; a n ] [ f ( a 0 ) ; . . . ; f ( a n )] ◮ The behavior of map σ,τ is independent from the types σ , τ . C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 3 / 12
System F Introduction Example (Map). ◮ Consider a map function ( σ → τ ) × list ( σ ) − → : list ( τ ) map σ,τ ( σ, τ types) � � �− → f , [ a 0 ; . . . ; a n ] [ f ( a 0 ) ; . . . ; f ( a n )] ◮ The behavior of map σ,τ is independent from the types σ , τ . ◮ One may want to have just one implementation, independent from σ and τ . C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 3 / 12
System F Introduction Example (Map). ◮ Consider a map function ( σ → τ ) × list ( σ ) − → : list ( τ ) map σ,τ ( σ, τ types) � � �− → f , [ a 0 ; . . . ; a n ] [ f ( a 0 ) ; . . . ; f ( a n )] ◮ The behavior of map σ,τ is independent from the types σ , τ . ◮ One may want to have just one implementation, independent from σ and τ . Example (Identity). ◮ Consider the typed terms id τ := λ x : τ. x : τ → τ and id σ := λ x : σ. x : σ → σ C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 3 / 12
System F Introduction Example (Map). ◮ Consider a map function ( σ → τ ) × list ( σ ) − → : list ( τ ) map σ,τ ( σ, τ types) � � �− → f , [ a 0 ; . . . ; a n ] [ f ( a 0 ) ; . . . ; f ( a n )] ◮ The behavior of map σ,τ is independent from the types σ , τ . ◮ One may want to have just one implementation, independent from σ and τ . Example (Identity). ◮ Consider the typed terms id τ := λ x : τ. x : τ → τ and id σ := λ x : σ. x : σ → σ ◮ These two term behave the same way. ◮ This behaviour is independent from σ, τ . C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 3 / 12
System F Introduction Example (Map). ◮ Consider a map function ( σ → τ ) × list ( σ ) − → : list ( τ ) map σ,τ ( σ, τ types) � � �− → f , [ a 0 ; . . . ; a n ] [ f ( a 0 ) ; . . . ; f ( a n )] ◮ The behavior of map σ,τ is independent from the types σ , τ . ◮ One may want to have just one implementation, independent from σ and τ . Example (Identity). ◮ Consider the typed terms id τ := λ x : τ. x : τ → τ and id σ := λ x : σ. x : σ → σ ◮ These two term behave the same way. ◮ This behaviour is independent from σ, τ . Main Idea: Polymorphism allows to express such uniformities using explicit universal quantification over types. C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 3 / 12
System F System F (Girard ’71, Reynolds ’74) C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 4 / 12
System F System F (Girard ’71, Reynolds ’74) Polymorphic Types. ◮ Assume given countably many type variables α, β, . . . C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 4 / 12
System F System F (Girard ’71, Reynolds ’74) Polymorphic Types. ◮ Assume given countably many type variables α, β, . . . ◮ Polymorphic types are given by τ, σ ::= α | σ → τ | ∀ α.σ C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 4 / 12
System F System F (Girard ’71, Reynolds ’74) Polymorphic Types. ◮ Assume given countably many type variables α, β, . . . ◮ Polymorphic types are given by τ, σ ::= α | σ → τ | ∀ α.σ Terms. | | t , u ::= x t u λ x : σ. t C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 4 / 12
System F System F (Girard ’71, Reynolds ’74) Polymorphic Types. ◮ Assume given countably many type variables α, β, . . . ◮ Polymorphic types are given by τ, σ ::= α | σ → τ | ∀ α.σ Terms. | | | | t , u ::= x t u λ x : σ. t Λ α. t t σ C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 4 / 12
System F System F (Girard ’71, Reynolds ’74) Polymorphic Types. ◮ Assume given countably many type variables α, β, . . . ◮ Polymorphic types are given by τ, σ ::= α | σ → τ | ∀ α.σ Terms. | | | | t , u ::= x t u λ x : σ. t Λ α. t t σ Typing Rules. ◮ Extension of the simply-typed systems with Γ ⊢ t : τ Γ ⊢ t : ∀ α.τ Γ ⊢ Λ α. t : ∀ α.τ ( α not free in Γ ) Γ ⊢ t σ : τ [ σ/α ] C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 4 / 12
System F System F (Girard ’71, Reynolds ’74) Polymorphic Types. ◮ Assume given countably many type variables α, β, . . . ◮ Polymorphic types are given by τ, σ ::= α | σ → τ | ∀ α.σ Terms. | | | | t , u ::= x t u λ x : σ. t Λ α. t t σ Typing Rules. ◮ Extension of the simply-typed systems with Γ ⊢ t : τ Γ ⊢ t : ∀ α.τ Γ ⊢ Λ α. t : ∀ α.τ ( α not free in Γ ) Γ ⊢ t σ : τ [ σ/α ] Reduction. ◮ We consider the full strong reduction ⊲ defined as t ⊲ u t ⊲ u t ⊲ u ( λ x : τ. t ) u ⊲ t [ u / x ] t v ⊲ u v v t ⊲ v u λ x : σ. t ⊲ λ x : σ. u t ⊲ u t ⊲ u (Λ α. t ) σ ⊲ t [ σ/α ] t σ ⊲ u σ Λ α. t ⊲ Λ α. u ◮ Let = β be the symmetric-reflexive-transitive closure of ⊲ . C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 4 / 12
System F Expressive Power ◮ The expressive power of System F is huge. We content ourselves with examples. C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 5 / 12
System F Expressive Power ◮ The expressive power of System F is huge. We content ourselves with examples. Identity. ◮ Let := Λ α.λ x : α. x : ∀ α ( α → α ) id � �� � Id For each τ we have id τ ⊲ id τ = λ x : τ. x : τ → τ In particular : Id → Id id Id C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 5 / 12
System F Expressive Power ◮ The expressive power of System F is huge. We content ourselves with examples. Identity. ◮ Let := Λ α.λ x : α. x : ∀ α ( α → α ) id � �� � Id For each τ we have id τ ⊲ id τ = λ x : τ. x : τ → τ In particular : Id → Id id Id Void Type. ◮ Let ⊥ := ∀ α.α . C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 5 / 12
System F Expressive Power ◮ The expressive power of System F is huge. We content ourselves with examples. Identity. ◮ Let := Λ α.λ x : α. x : ∀ α ( α → α ) id � �� � Id For each τ we have id τ ⊲ id τ = λ x : τ. x : τ → τ In particular : Id → Id id Id Void Type. ◮ Let ⊥ := ∀ α.α . We have Γ ⊢ t : ⊥ Γ ⊢ t τ : τ ◮ Question. Is there a closed term of type ⊥ ? C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 5 / 12
System F Product Types Let � � τ × σ := ∀ α. ( τ → σ → α ) − → α C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 6 / 12
System F Product Types Let � � τ × σ := ∀ α. ( τ → σ → α ) − → α pair t u := so that Γ ⊢ t : τ Γ ⊢ u : σ Γ ⊢ pair t u : τ × σ C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 6 / 12
System F Product Types Let � � τ × σ := ∀ α. ( τ → σ → α ) − → α pair t u := Λ α. λ p : τ → σ → α. p t u so that Γ ⊢ t : τ Γ ⊢ u : σ Γ ⊢ pair t u : τ × σ C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 6 / 12
System F Product Types Let � � τ × σ := ∀ α. ( τ → σ → α ) − → α pair t u := Λ α. λ p : τ → σ → α. p t u π 1 t := so that Γ ⊢ t : τ Γ ⊢ u : σ Γ ⊢ t : τ × σ Γ ⊢ pair t u : τ × σ Γ ⊢ π 1 t : τ C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 6 / 12
System F Product Types Let � � τ × σ := ∀ α. ( τ → σ → α ) − → α pair t u := Λ α. λ p : τ → σ → α. p t u π 1 t := t τ ( λ x : τ. λ y : σ. x ) so that Γ ⊢ t : τ Γ ⊢ u : σ Γ ⊢ t : τ × σ Γ ⊢ pair t u : τ × σ Γ ⊢ π 1 t : τ C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 6 / 12
Recommend
More recommend