advanced semantics of programming languages
play

Advanced Semantics of Programming Languages Pierre C LAIRAMBAULT - PowerPoint PPT Presentation

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


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

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

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

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

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

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

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

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

  9. System F System F (Girard ’71, Reynolds ’74) C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 4 / 12

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

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

  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

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

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

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

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

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

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

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

  20. System F Product Types Let � � τ × σ := ∀ α. ( τ → σ → α ) − → α C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 13 12/11 6 / 12

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

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

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

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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend