reynolds parametricity
play

Reynolds Parametricity Patricia Johann Appalachian State University - PowerPoint PPT Presentation

Reynolds Parametricity Patricia Johann Appalachian State University cs.appstate.edu/ johannp Based on joint work with Neil Ghani, Fredrik Nordvall Forsberg, Federico Orsanigo, and Tim Revell OPLSS 2016 Course Outline Topic:


  1. Type Contexts and Judgements • A type context ∆ is a list of type variables α 1 , ..., α n • A type judgement ∆ ⊢ τ has – ∆ a type context – τ a type • Type judgements are defined inductively: ∆ , α ⊢ τ α i ∈ ∆ ∆ ⊢ τ 1 ∆ ⊢ τ 2 ∆ ⊢ α i ∆ ⊢ τ 1 → τ 2 ∆ ⊢ ∀ α.τ • We consider α -convertible types equivalent

  2. Term Contexts and Judgements - Part I • A term context ∆ ⊢ Γ has – ∆ a type context – x 1 , ..., x m term variables – Γ of the form x 1 : τ 1 , ..., x m : τ m – ∆ ⊢ τ i for each i ∈ { 1 , ..., m }

  3. Term Contexts and Judgements - Part I • A term context ∆ ⊢ Γ has – ∆ a type context – x 1 , ..., x m term variables – Γ of the form x 1 : τ 1 , ..., x m : τ m – ∆ ⊢ τ i for each i ∈ { 1 , ..., m } • A term judgement ∆; Γ ⊢ t : τ has – ∆ a type context – ∆ ⊢ Γ a term context – ∆ ⊢ τ a type judgement – t a term

  4. Term Contexts and Judgements - Part II • Term judgements are defined inductively: ∆; Γ , x : τ 1 ⊢ t : τ 2 ∆; Γ ⊢ t 1 : τ 1 ∆; Γ ⊢ t 2 : τ 1 → τ 2 ∆ ⊢ τ i x i : τ i ∈ Γ ∆; Γ ⊢ x i : τ i ∆; Γ ⊢ λx.t : τ 1 → τ 2 ∆; Γ ⊢ t 2 t 1 : τ 2 ∆; Γ ⊢ t : ∀ α.τ 2 ∆ ⊢ τ 1 ∆ , α ; Γ ⊢ t : τ ∆; Γ ⊢ Λ α.t : ∀ α.τ ∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ]

  5. Term Contexts and Judgements - Part II • Term judgements are defined inductively: ∆; Γ , x : τ 1 ⊢ t : τ 2 ∆; Γ ⊢ t 1 : τ 1 ∆; Γ ⊢ t 2 : τ 1 → τ 2 ∆ ⊢ τ i x i : τ i ∈ Γ ∆; Γ ⊢ x i : τ i ∆; Γ ⊢ λx.t : τ 1 → τ 2 ∆; Γ ⊢ t 2 t 1 : τ 2 ∆; Γ ⊢ t : ∀ α.τ 2 ∆ ⊢ τ 1 ∆ , α ; Γ ⊢ t : τ ∆; Γ ⊢ Λ α.t : ∀ α.τ ∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ] • Type abstraction requires that α does not appear (free) in Γ

  6. Term Contexts and Judgements - Part II • Term judgements are defined inductively: ∆; Γ , x : τ 1 ⊢ t : τ 2 ∆; Γ ⊢ t 1 : τ 1 ∆; Γ ⊢ t 2 : τ 1 → τ 2 ∆ ⊢ τ i x i : τ i ∈ Γ ∆; Γ ⊢ x i : τ i ∆; Γ ⊢ λx.t : τ 1 → τ 2 ∆; Γ ⊢ t 2 t 1 : τ 2 ∆; Γ ⊢ t : ∀ α.τ 2 ∆ ⊢ τ 1 ∆ , α ; Γ ⊢ t : τ ∆; Γ ⊢ Λ α.t : ∀ α.τ ∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ] • Type abstraction requires that α does not appear (free) in Γ • τ 2 [ α �→ τ 1 ], t [ α �→ τ 1 ], and t [ x �→ y ] denote (capture-free) substitution

  7. Conversion Rules - Part I ( α λ ) ∆; Γ ⊢ Λ α 1 . t = Λ α 2 . t [ α 1 �→ α 2 ] : ∀ α 1 .τ ( α Λ ) ∆; Γ ⊢ λx. t = λy. t [ x �→ y ] : τ 1 → τ 2 ( β λ ) ∆; Γ ⊢ (Λ α. t ) τ 1 = t : τ 2 [ α �→ τ 1 ] ( β Λ ) ∆; Γ ⊢ ( λx. t ) s = t [ x �→ s ] : τ 2 x / ∈ F V ( t ) α / ∈ F T V ( t ) ∆; Γ ⊢ t = λx. t x : τ 1 → τ 2 ( η λ ) ∆; Γ ⊢ t = Λ α. t α : ∀ α.τ ( η Λ ) ∆; Γ , x : τ 1 ⊢ t 1 = t 2 : τ 2 ∆ , α ; Γ ⊢ t 1 = t 2 : τ ∆; Γ ⊢ λx. t 1 = λx. t 2 : τ 1 → τ 2 ( ξ λ ) ∆; Γ ⊢ Λ α. t 1 = Λ α. t 2 : ∀ α.τ ( ξ Λ )

  8. Conversion Rules - Part II ∆; Γ ⊢ t 1 = t 2 : τ 1 → τ 2 ∆; Γ ⊢ s 1 = s 2 : τ 1 (cong λ ) ∆; Γ ⊢ t 1 s 1 = t 2 s 2 : τ 2 ∆; Γ ⊢ t 1 = t 2 : ∀ α.τ 2 ∆; Γ ⊢ t 1 τ 1 = t 2 τ 1 : τ 2 [ α �→ τ 1 ] (cong Λ ) ∆; Γ ⊢ s = t : τ ∆; Γ ⊢ t = t : τ (refl) ∆; Γ ⊢ t = s : τ (sym) ∆; Γ ⊢ t = s : τ Γ; ∆ ⊢ s = u : τ (trans) ∆; Γ ⊢ t = u : τ

  9. Reynolds’ Semantics of Types - The Set Up • Reynolds defines two “parallel” semantics for System F types ∆ ⊢ τ

  10. Reynolds’ Semantics of Types - The Set Up • Reynolds defines two “parallel” semantics for System F types ∆ ⊢ τ ] o : Set | ∆ | → Set – an object semantics [ [∆ ⊢ τ ]

  11. Reynolds’ Semantics of Types - The Set Up • Reynolds defines two “parallel” semantics for System F types ∆ ⊢ τ ] o : Set | ∆ | → Set – an object semantics [ [∆ ⊢ τ ] ] r : Rel | ∆ | → Rel – a relational semantics [ [∆ ⊢ τ ]

  12. Reynolds’ Semantics of Types - The Set Up • Reynolds defines two “parallel” semantics for System F types ∆ ⊢ τ ] o : Set | ∆ | → Set – an object semantics [ [∆ ⊢ τ ] ] r : Rel | ∆ | → Rel – a relational semantics [ [∆ ⊢ τ ] • Write – S : Set if S is a set – R : Rel if R is a relation – R : Rel ( X, Y ) if R is a relation on sets X and Y (i.e., R ⊆ X × Y )

  13. Reynolds’ Semantics of Types - The Set Up • Reynolds defines two “parallel” semantics for System F types ∆ ⊢ τ ] o : Set | ∆ | → Set – an object semantics [ [∆ ⊢ τ ] ] r : Rel | ∆ | → Rel – a relational semantics [ [∆ ⊢ τ ] • Write – S : Set if S is a set – R : Rel if R is a relation – R : Rel ( X, Y ) if R is a relation on sets X and Y (i.e., R ⊆ X × Y ) • Let – X be a | ∆ | -tuple of sets – R be a | ∆ | -tuple of relations – R i : Rel ( X i , Y i ) for i = 1 , ..., | ∆ | – Eq X = { ( x, x ) | x ∈ X }

  14. Reynolds’ Semantics of Types • Type variables: [ [∆ ⊢ α i ] ] o X = X i and [ [∆ ⊢ α i ] ] r R = R i

  15. Reynolds’ Semantics of Types • Type variables: [ [∆ ⊢ α i ] ] o X = X i and [ [∆ ⊢ α i ] ] r R = R i • Arrow types: − [ [∆ ⊢ τ 1 → τ 2 ] ] o X = [ [∆ ⊢ τ 1 ] ] o X → [ [∆ ⊢ τ 2 ] ] o X

  16. Reynolds’ Semantics of Types • Type variables: [ [∆ ⊢ α i ] ] o X = X i and [ [∆ ⊢ α i ] ] r R = R i • Arrow types: − [ [∆ ⊢ τ 1 → τ 2 ] ] o X = [ [∆ ⊢ τ 1 ] ] o X → [ [∆ ⊢ τ 2 ] ] o X − [ [∆ ⊢ τ 1 → τ 2 ] ] r R = { ( f, g ) | ( a, b ) ∈ [ [∆ ⊢ τ 1 ] ] r R ⇒ ( f a, g b ) ∈ [ [∆ ⊢ τ 2 ] ] r R }

  17. Reynolds’ Semantics of Types • Type variables: [ [∆ ⊢ α i ] ] o X = X i and [ [∆ ⊢ α i ] ] r R = R i • Arrow types: − [ [∆ ⊢ τ 1 → τ 2 ] ] o X = [ [∆ ⊢ τ 1 ] ] o X → [ [∆ ⊢ τ 2 ] ] o X − [ [∆ ⊢ τ 1 → τ 2 ] ] r R = { ( f, g ) | ( a, b ) ∈ [ [∆ ⊢ τ 1 ] ] r R ⇒ ( f a, g b ) ∈ [ [∆ ⊢ τ 2 ] ] r R } Here, f ∈ [ [∆ ⊢ τ 1 → τ 2 ] ] o X and g ∈ [ [∆ ⊢ τ 1 → τ 2 ] ] o Y

  18. Reynolds’ Semantics of Types • Type variables: [ [∆ ⊢ α i ] ] o X = X i and [ [∆ ⊢ α i ] ] r R = R i • Arrow types: − [ [∆ ⊢ τ 1 → τ 2 ] ] o X = [ [∆ ⊢ τ 1 ] ] o X → [ [∆ ⊢ τ 2 ] ] o X − [ [∆ ⊢ τ 1 → τ 2 ] ] r R = { ( f, g ) | ( a, b ) ∈ [ [∆ ⊢ τ 1 ] ] r R ⇒ ( f a, g b ) ∈ [ [∆ ⊢ τ 2 ] ] r R } Here, f ∈ [ [∆ ⊢ τ 1 → τ 2 ] ] o X and g ∈ [ [∆ ⊢ τ 1 → τ 2 ] ] o Y • Forall types: � − [ [∆ ⊢ ∀ α.τ ] ] o X = { f : [ [∆ , α ⊢ τ ] ] o ( X, S ) | S : Set ∀ R ′ : Rel ( X ′ , Y ′ ) . ( fX ′ , fY ′ ) ∈ [ ] r ( Eq X, R ′ ) } [∆ , α ⊢ τ ]

  19. Reynolds’ Semantics of Types • Type variables: [ [∆ ⊢ α i ] ] o X = X i and [ [∆ ⊢ α i ] ] r R = R i • Arrow types: − [ [∆ ⊢ τ 1 → τ 2 ] ] o X = [ [∆ ⊢ τ 1 ] ] o X → [ [∆ ⊢ τ 2 ] ] o X − [ [∆ ⊢ τ 1 → τ 2 ] ] r R = { ( f, g ) | ( a, b ) ∈ [ [∆ ⊢ τ 1 ] ] r R ⇒ ( f a, g b ) ∈ [ [∆ ⊢ τ 2 ] ] r R } Here, f ∈ [ [∆ ⊢ τ 1 → τ 2 ] ] o X and g ∈ [ [∆ ⊢ τ 1 → τ 2 ] ] o Y • Forall types: � − [ [∆ ⊢ ∀ α.τ ] ] o X = { f : [ [∆ , α ⊢ τ ] ] o ( X, S ) | S : Set ∀ R ′ : Rel ( X ′ , Y ′ ) . ( fX ′ , fY ′ ) ∈ [ ] r ( Eq X, R ′ ) } [∆ , α ⊢ τ ] ] r R = { ( f, g ) | ∀ R ′ : Rel ( X ′ , Y ′ ) . ( fX ′ , gY ′ ) ∈ [ ] r ( R, R ′ ) } − [ [∆ ⊢ ∀ α.τ ] [∆ , α ⊢ τ ]

  20. Reynolds’ Semantics of Types • Type variables: [ [∆ ⊢ α i ] ] o X = X i and [ [∆ ⊢ α i ] ] r R = R i • Arrow types: − [ [∆ ⊢ τ 1 → τ 2 ] ] o X = [ [∆ ⊢ τ 1 ] ] o X → [ [∆ ⊢ τ 2 ] ] o X − [ [∆ ⊢ τ 1 → τ 2 ] ] r R = { ( f, g ) | ( a, b ) ∈ [ [∆ ⊢ τ 1 ] ] r R ⇒ ( f a, g b ) ∈ [ [∆ ⊢ τ 2 ] ] r R } Here, f ∈ [ [∆ ⊢ τ 1 → τ 2 ] ] o X and g ∈ [ [∆ ⊢ τ 1 → τ 2 ] ] o Y • Forall types: � − [ [∆ ⊢ ∀ α.τ ] ] o X = { f : [ [∆ , α ⊢ τ ] ] o ( X, S ) | S : Set ∀ R ′ : Rel ( X ′ , Y ′ ) . ( fX ′ , fY ′ ) ∈ [ ] r ( Eq X, R ′ ) } [∆ , α ⊢ τ ] ] r R = { ( f, g ) | ∀ R ′ : Rel ( X ′ , Y ′ ) . ( fX ′ , gY ′ ) ∈ [ ] r ( R, R ′ ) } − [ [∆ ⊢ ∀ α.τ ] [∆ , α ⊢ τ ] Here, f ∈ [ [∆ ⊢ ∀ α.τ ] ] o X and g ∈ [ [∆ ⊢ ∀ α.τ ] ] o Y

  21. Some Observations • By construction, relational interpretations of functions (on types and on terms) map related inputs to related outputs

  22. Some Observations • By construction, relational interpretations of functions (on types and on terms) map related inputs to related outputs • If R : Rel ( X, Y ) then [ [∆ ⊢ τ ] ] r R : Rel ([ [∆ ⊢ τ ] ] o X, [ [∆ ⊢ τ ] ] o Y )

  23. Some Observations • By construction, relational interpretations of functions (on types and on terms) map related inputs to related outputs • If R : Rel ( X, Y ) then [ [∆ ⊢ τ ] ] r R : Rel ([ [∆ ⊢ τ ] ] o X, [ [∆ ⊢ τ ] ] o Y ) • The two interpretations of terms get progressively more intertwined:

  24. Some Observations • By construction, relational interpretations of functions (on types and on terms) map related inputs to related outputs • If R : Rel ( X, Y ) then [ [∆ ⊢ τ ] ] r R : Rel ([ [∆ ⊢ τ ] ] o X, [ [∆ ⊢ τ ] ] o Y ) • The two interpretations of terms get progressively more intertwined: – The object and relational interpretations of type variables are inde- pendent of one another

  25. Some Observations • By construction, relational interpretations of functions (on types and on terms) map related inputs to related outputs • If R : Rel ( X, Y ) then [ [∆ ⊢ τ ] ] r R : Rel ([ [∆ ⊢ τ ] ] o X, [ [∆ ⊢ τ ] ] o Y ) • The two interpretations of terms get progressively more intertwined: – The object and relational interpretations of type variables are inde- pendent of one another – The object interpretation of an arrow type does not depend on its relational interpretation, but the relational interpretation of an arrow type does depend on its object interpretation

  26. Some Observations • By construction, relational interpretations of functions (on types and on terms) map related inputs to related outputs • If R : Rel ( X, Y ) then [ [∆ ⊢ τ ] ] r R : Rel ([ [∆ ⊢ τ ] ] o X, [ [∆ ⊢ τ ] ] o Y ) • The two interpretations of terms get progressively more intertwined: – The object and relational interpretations of type variables are inde- pendent of one another – The object interpretation of an arrow type does not depend on its relational interpretation, but the relational interpretation of an arrow type does depend on its object interpretation – The object and relational interpretations of forall types depend crucially on one another

  27. Some Observations • By construction, relational interpretations of functions (on types and on terms) map related inputs to related outputs • If R : Rel ( X, Y ) then [ [∆ ⊢ τ ] ] r R : Rel ([ [∆ ⊢ τ ] ] o X, [ [∆ ⊢ τ ] ] o Y ) • The two interpretations of terms get progressively more intertwined: – The object and relational interpretations of type variables are inde- pendent of one another – The object interpretation of an arrow type does not depend on its relational interpretation, but the relational interpretation of an arrow type does depend on its object interpretation – The object and relational interpretations of forall types depend crucially on one another • So we do not really have two semantics, but rather a single intercon- nected semantics!

  28. Identity Extension Lemma • Key for many applications of parametricity

  29. Identity Extension Lemma • Key for many applications of parametricity • Intuitively, relational interpretations of types preserve equality

  30. Identity Extension Lemma • Key for many applications of parametricity • Intuitively, relational interpretations of types preserve equality • Theorem (Identity Extension Lemma) For all ∆ ⊢ τ , [ [∆ ⊢ τ ] ] r ( Eq X 1 , ..., Eq X | ∆ | ) = Eq ([ [∆ ⊢ τ ] ] o ( X 1 , ..., X | ∆ | ))

  31. Reynolds’ Semantics of Terms - The Set Up • Object and relational interpretations of term contexts Γ = x 1 : τ 1 , . . . , x m : τ m are given by [ [∆ ⊢ Γ] ] o = [ [∆ ⊢ τ 1 ] ] o × · · · × [ [∆ ⊢ τ m ] ] o and [ [∆ ⊢ Γ] ] r = [ [∆ ⊢ τ 1 ] ] r × · · · × [ [∆ ⊢ τ m ] ] r

  32. Reynolds’ Semantics of Terms - The Set Up • Object and relational interpretations of term contexts Γ = x 1 : τ 1 , . . . , x m : τ m are given by [ [∆ ⊢ Γ] ] o = [ [∆ ⊢ τ 1 ] ] o × · · · × [ [∆ ⊢ τ m ] ] o and [ [∆ ⊢ Γ] ] r = [ [∆ ⊢ τ 1 ] ] r × · · · × [ [∆ ⊢ τ m ] ] r • An object interpretation of each term is a family of functions [ [∆; Γ ⊢ t : τ ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ ] ] o X parameterized over a set environment X

  33. Reynolds’ Semantics of Terms - The Set Up • Object and relational interpretations of term contexts Γ = x 1 : τ 1 , . . . , x m : τ m are given by [ [∆ ⊢ Γ] ] o = [ [∆ ⊢ τ 1 ] ] o × · · · × [ [∆ ⊢ τ m ] ] o and [ [∆ ⊢ Γ] ] r = [ [∆ ⊢ τ 1 ] ] r × · · · × [ [∆ ⊢ τ m ] ] r • An object interpretation of each term is a family of functions [ [∆; Γ ⊢ t : τ ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ ] ] o X parameterized over a set environment X • We’ll sanity-check the definitions as we go along

  34. Reynolds’ Semantics of Terms - variables • If ∆; Γ ⊢ x i : τ i then [ [∆; Γ ⊢ x i : τ i ] ] o X A = A i

  35. Reynolds’ Semantics of Terms - variables • If ∆; Γ ⊢ x i : τ i then [ [∆; Γ ⊢ x i : τ i ] ] o X A = A i • This is sensible because we want [ [∆; Γ ⊢ x i : τ i ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ i ] ] o X

  36. Reynolds’ Semantics of Terms - variables • If ∆; Γ ⊢ x i : τ i then [ [∆; Γ ⊢ x i : τ i ] ] o X A = A i • This is sensible because we want [ [∆; Γ ⊢ x i : τ i ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ i ] ] o X and because if A : [ [∆ ⊢ Γ] ] o X , then A i : [ [∆ ⊢ τ i ] ] o X

  37. Reynolds’ Semantics of Terms - term abstractions • If ∆; Γ , x : τ 1 ⊢ t : τ 2 ∆; Γ ⊢ λx.t : τ 1 → τ 2 then [ [∆; Γ ⊢ λx.t : τ 1 → τ 2 ] ] o X A A = [ [∆; Γ , x : τ 1 ⊢ t : τ 2 ] ] o X ( A, A )

  38. Reynolds’ Semantics of Terms - term abstractions • If ∆; Γ , x : τ 1 ⊢ t : τ 2 ∆; Γ ⊢ λx.t : τ 1 → τ 2 then [ [∆; Γ ⊢ λx.t : τ 1 → τ 2 ] ] o X A A = [ [∆; Γ , x : τ 1 ⊢ t : τ 2 ] ] o X ( A, A ) • This is sensible because we want [ [∆; Γ ⊢ λx.t : τ 1 → τ 2 ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ 1 → τ 2 ] ] o X = [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ 1 ] ] o X → [ [∆ ⊢ τ 2 ] ] o X

  39. Reynolds’ Semantics of Terms - term abstractions • If ∆; Γ , x : τ 1 ⊢ t : τ 2 ∆; Γ ⊢ λx.t : τ 1 → τ 2 then [ [∆; Γ ⊢ λx.t : τ 1 → τ 2 ] ] o X A A = [ [∆; Γ , x : τ 1 ⊢ t : τ 2 ] ] o X ( A, A ) • This is sensible because we want [ [∆; Γ ⊢ λx.t : τ 1 → τ 2 ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ 1 → τ 2 ] ] o X = [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ 1 ] ] o X → [ [∆ ⊢ τ 2 ] ] o X and because the IH gives [ [∆; Γ , x : τ 1 ⊢ t : τ 2 ] ] o X : [ [∆ ⊢ Γ] ] o X × [ [∆ ⊢ τ 1 ] ] o X → [ [∆ ⊢ τ 2 ] ] o X

  40. Reynolds’ Semantics of Terms - term applications • If ∆; Γ ⊢ t 1 : τ 1 ∆; Γ ⊢ t 2 : τ 1 → τ 2 ∆; Γ ⊢ t 2 t 1 : τ 2 then [ [∆; Γ ⊢ t 2 t 1 : τ 2 ] ] o X A = [ [∆; Γ ⊢ t 2 : τ 1 → τ 2 ] ] o X A ([ [∆; Γ ⊢ t 1 : τ 1 ] ] o X A )

  41. Reynolds’ Semantics of Terms - term applications • If ∆; Γ ⊢ t 1 : τ 1 ∆; Γ ⊢ t 2 : τ 1 → τ 2 ∆; Γ ⊢ t 2 t 1 : τ 2 then [ [∆; Γ ⊢ t 2 t 1 : τ 2 ] ] o X A = [ [∆; Γ ⊢ t 2 : τ 1 → τ 2 ] ] o X A ([ [∆; Γ ⊢ t 1 : τ 1 ] ] o X A ) • This is sensible because we want [ [∆; Γ ⊢ t 2 t 1 : τ 2 ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ 2 ] ] o X

  42. Reynolds’ Semantics of Terms - term applications • If ∆; Γ ⊢ t 1 : τ 1 ∆; Γ ⊢ t 2 : τ 1 → τ 2 ∆; Γ ⊢ t 2 t 1 : τ 2 then [ [∆; Γ ⊢ t 2 t 1 : τ 2 ] ] o X A = [ [∆; Γ ⊢ t 2 : τ 1 → τ 2 ] ] o X A ([ [∆; Γ ⊢ t 1 : τ 1 ] ] o X A ) • This is sensible because we want [ [∆; Γ ⊢ t 2 t 1 : τ 2 ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ 2 ] ] o X and because the IH gives [ [∆; Γ ⊢ t 2 : τ 1 → τ 2 ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ 1 → τ 2 ] ] o X = [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ 1 ] ] o X → [ [∆ ⊢ τ 2 ] ] o X

  43. Reynolds’ Semantics of Terms - term applications • If ∆; Γ ⊢ t 1 : τ 1 ∆; Γ ⊢ t 2 : τ 1 → τ 2 ∆; Γ ⊢ t 2 t 1 : τ 2 then [ [∆; Γ ⊢ t 2 t 1 : τ 2 ] ] o X A = [ [∆; Γ ⊢ t 2 : τ 1 → τ 2 ] ] o X A ([ [∆; Γ ⊢ t 1 : τ 1 ] ] o X A ) • This is sensible because we want [ [∆; Γ ⊢ t 2 t 1 : τ 2 ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ 2 ] ] o X and because the IH gives [ [∆; Γ ⊢ t 2 : τ 1 → τ 2 ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ 1 → τ 2 ] ] o X = [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ 1 ] ] o X → [ [∆ ⊢ τ 2 ] ] o X and [ [∆; Γ ⊢ t 1 : τ 1 ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ 1 ] ] o X

  44. Taking Stock • So far, term interpretations are all in the required sets

  45. Taking Stock • So far, term interpretations are all in the required sets • But when Reynolds interpreted type abstractions and applications

  46. Taking Stock • So far, term interpretations are all in the required sets • But when Reynolds interpreted type abstractions and applications ... and tried to show that term interpretations are in the required sets

  47. Taking Stock • So far, term interpretations are all in the required sets • But when Reynolds interpreted type abstractions and applications ... and tried to show that term interpretations are in the required sets ... he ran into problems

  48. Reynolds’ Semantics of Terms - type abstractions • If ∆ , α ; Γ ⊢ t : τ ∆; Γ ⊢ Λ α.t : ∀ α.τ then [ [∆; Γ ⊢ Λ α.t : ∀ α.τ ] ] o X A = Π S : Set [ [∆ , α ; Γ ⊢ t : τ ] ] o ( X, S ) A

  49. Reynolds’ Semantics of Terms - type abstractions • If ∆ , α ; Γ ⊢ t : τ ∆; Γ ⊢ Λ α.t : ∀ α.τ then [ [∆; Γ ⊢ Λ α.t : ∀ α.τ ] ] o X A = Π S : Set [ [∆ , α ; Γ ⊢ t : τ ] ] o ( X, S ) A • This is sensible because we want [ [∆; Γ ⊢ Λ α.t : ∀ α.τ ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ ∀ α.τ ] ] o X = [ [∆ ⊢ Γ] ] o X → { f : Π S : Set [ [∆ , α ⊢ τ ] ] o ( X, S ) | ... }

  50. Reynolds’ Semantics of Terms - type abstractions • If ∆ , α ; Γ ⊢ t : τ ∆; Γ ⊢ Λ α.t : ∀ α.τ then [ [∆; Γ ⊢ Λ α.t : ∀ α.τ ] ] o X A = Π S : Set [ [∆ , α ; Γ ⊢ t : τ ] ] o ( X, S ) A • This is sensible because we want [ [∆; Γ ⊢ Λ α.t : ∀ α.τ ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ ∀ α.τ ] ] o X = [ [∆ ⊢ Γ] ] o X → { f : Π S : Set [ [∆ , α ⊢ τ ] ] o ( X, S ) | ... } and because α not free in Γ implies [ [∆ , α ; Γ ⊢ t : τ ] ] o ( X, S ) : [ [∆ , α ⊢ Γ] ] o ( X, S ) → [ [∆ , α ⊢ τ ] ] o ( X, S ) = [ [∆ ⊢ Γ] ] o X → [ [∆ , α ⊢ τ ] ] o ( X, S )

  51. Reynolds’ Semantics of Terms - type abstractions • If ∆ , α ; Γ ⊢ t : τ ∆; Γ ⊢ Λ α.t : ∀ α.τ then [ [∆; Γ ⊢ Λ α.t : ∀ α.τ ] ] o X A = Π S : Set [ [∆ , α ; Γ ⊢ t : τ ] ] o ( X, S ) A • This is sensible because we want [ [∆; Γ ⊢ Λ α.t : ∀ α.τ ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ ∀ α.τ ] ] o X = [ [∆ ⊢ Γ] ] o X → { f : Π S : Set [ [∆ , α ⊢ τ ] ] o ( X, S ) | ... } and because α not free in Γ implies [ [∆ , α ; Γ ⊢ t : τ ] ] o ( X, S ) : [ [∆ , α ⊢ Γ] ] o ( X, S ) → [ [∆ , α ⊢ τ ] ] o ( X, S ) = [ [∆ ⊢ Γ] ] o X → [ [∆ , α ⊢ τ ] ] o ( X, S ) • But now we’d have to check that the condition after the vertical bar in the set interpretation of a ∀ -type holds...

  52. Reynolds’ Semantics of Terms - type applications • If ∆; Γ ⊢ t : ∀ α.τ 2 ∆ ⊢ τ 1 ∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ] then [ [∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ]] ] o X A = [ [∆; Γ ⊢ t : ∀ α.τ 2 ] ] o X A ([ [∆ ⊢ τ 1 ] ] o X )

  53. Reynolds’ Semantics of Terms - type applications • If ∆; Γ ⊢ t : ∀ α.τ 2 ∆ ⊢ τ 1 ∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ] then [ [∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ]] ] o X A = [ [∆; Γ ⊢ t : ∀ α.τ 2 ] ] o X A ([ [∆ ⊢ τ 1 ] ] o X ) • This is sensible because we want [ [∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ]] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ 2 [ α �→ τ 1 ]] ] o X

  54. Reynolds’ Semantics of Terms - type applications • If ∆; Γ ⊢ t : ∀ α.τ 2 ∆ ⊢ τ 1 ∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ] then [ [∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ]] ] o X A = [ [∆; Γ ⊢ t : ∀ α.τ 2 ] ] o X A ([ [∆ ⊢ τ 1 ] ] o X ) • This is sensible because we want [ [∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ]] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ 2 [ α �→ τ 1 ]] ] o X and because [ [∆; Γ ⊢ t : ∀ α.τ 2 ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ ∀ α.τ 2 ] ] o X = [ [∆ ⊢ Γ] ] o X → { f : Π S : Set [ [∆ , α ⊢ τ 2 ] ] o ( X, S ) | ... }

  55. Reynolds’ Semantics of Terms - type applications • If ∆; Γ ⊢ t : ∀ α.τ 2 ∆ ⊢ τ 1 ∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ] then [ [∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ]] ] o X A = [ [∆; Γ ⊢ t : ∀ α.τ 2 ] ] o X A ([ [∆ ⊢ τ 1 ] ] o X ) • This is sensible because we want [ [∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ]] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ 2 [ α �→ τ 1 ]] ] o X and because [ [∆; Γ ⊢ t : ∀ α.τ 2 ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ ∀ α.τ 2 ] ] o X = [ [∆ ⊢ Γ] ] o X → { f : Π S : Set [ [∆ , α ⊢ τ 2 ] ] o ( X, S ) | ... } • To type-check this, we’d need to show [ [∆; Γ ⊢ t : ∀ α.τ 2 ] ] o X A ([ [∆ ⊢ τ 1 ] ] o X ) : [ [∆ ⊢ τ 2 [ α �→ τ 1 ]] ] o X

  56. Reynolds’ Semantics of Terms - type applications • If ∆; Γ ⊢ t : ∀ α.τ 2 ∆ ⊢ τ 1 ∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ] then [ [∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ]] ] o X A = [ [∆; Γ ⊢ t : ∀ α.τ 2 ] ] o X A ([ [∆ ⊢ τ 1 ] ] o X ) • This is sensible because we want [ [∆; Γ ⊢ t τ 1 : τ 2 [ α �→ τ 1 ]] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ τ 2 [ α �→ τ 1 ]] ] o X and because [ [∆; Γ ⊢ t : ∀ α.τ 2 ] ] o X : [ [∆ ⊢ Γ] ] o X → [ [∆ ⊢ ∀ α.τ 2 ] ] o X = [ [∆ ⊢ Γ] ] o X → { f : Π S : Set [ [∆ , α ⊢ τ 2 ] ] o ( X, S ) | ... } • To type-check this, we’d need to show [ [∆; Γ ⊢ t : ∀ α.τ 2 ] ] o X A ([ [∆ ⊢ τ 1 ] ] o X ) : [ [∆ ⊢ τ 2 [ α �→ τ 1 ]] ] o X • But this assumes the interpretation of type abstractions is sensible...

  57. What About Type Abstractions and Applications? • Due to size considerations, Reynolds cannot interpret ∀ α.τ as a set of the form Π S ∈ Set S for the usual set-theoretic product

  58. What About Type Abstractions and Applications? • Due to size considerations, Reynolds cannot interpret ∀ α.τ as a set of the form Π S ∈ Set S for the usual set-theoretic product – α would have to range over all sets interpreting types... including the set interpreting ∀ α.τ !

  59. What About Type Abstractions and Applications? • Due to size considerations, Reynolds cannot interpret ∀ α.τ as a set of the form Π S ∈ Set S for the usual set-theoretic product – α would have to range over all sets interpreting types... including the set interpreting ∀ α.τ ! – This is impossible!

  60. What About Type Abstractions and Applications? • Due to size considerations, Reynolds cannot interpret ∀ α.τ as a set of the form Π S ∈ Set S for the usual set-theoretic product – α would have to range over all sets interpreting types... including the set interpreting ∀ α.τ ! – This is impossible! • Idea: Maybe a weaker notion of “large” product can interpret ∀ α.τ while still preserving the usual binary product and function space?

  61. What About Type Abstractions and Applications? • Due to size considerations, Reynolds cannot interpret ∀ α.τ as a set of the form Π S ∈ Set S for the usual set-theoretic product – α would have to range over all sets interpreting types... including the set interpreting ∀ α.τ ! – This is impossible! • Idea: Maybe a weaker notion of “large” product can interpret ∀ α.τ while still preserving the usual binary product and function space? • In order to exclude ad hoc polymorphic functions from his model, Reynolds restricts it by imposing a so-called parametricity property

  62. What About Type Abstractions and Applications? • Due to size considerations, Reynolds cannot interpret ∀ α.τ as a set of the form Π S ∈ Set S for the usual set-theoretic product – α would have to range over all sets interpreting types... including the set interpreting ∀ α.τ ! – This is impossible! • Idea: Maybe a weaker notion of “large” product can interpret ∀ α.τ while still preserving the usual binary product and function space? • In order to exclude ad hoc polymorphic functions from his model, Reynolds restricts it by imposing a so-called parametricity property • This leads to the interpretations we have seen

  63. What About Type Abstractions and Applications? • Due to size considerations, Reynolds cannot interpret ∀ α.τ as a set of the form Π S ∈ Set S for the usual set-theoretic product – α would have to range over all sets interpreting types... including the set interpreting ∀ α.τ ! – This is impossible! • Idea: Maybe a weaker notion of “large” product can interpret ∀ α.τ while still preserving the usual binary product and function space? • In order to exclude ad hoc polymorphic functions from his model, Reynolds restricts it by imposing a so-called parametricity property • This leads to the interpretations we have seen • Conjecturing that these definitions give a sensible model, Reynolds proves his Abstraction Theorem

  64. Problems in Parametricity Paradise • The next year Reynolds discovered that there can be no set model of System F in which – × is interpreted as the usual binary product – → is the interpreted as the usual function space – ∀ α.τ is interpreted as a possibly restricted “large” product

  65. Problems in Parametricity Paradise • The next year Reynolds discovered that there can be no set model of System F in which – × is interpreted as the usual binary product – → is the interpreted as the usual function space – ∀ α.τ is interpreted as a possibly restricted “large” product • This is the case no matter what notion of “parametric” is used to restrict “large” products to exclude ad hoc functions!

  66. Problems in Parametricity Paradise • The next year Reynolds discovered that there can be no set model of System F in which – × is interpreted as the usual binary product – → is the interpreted as the usual function space – ∀ α.τ is interpreted as a possibly restricted “large” product • This is the case no matter what notion of “parametric” is used to restrict “large” products to exclude ad hoc functions! • Reynolds proved this working in a classical set theory

  67. Problems in Parametricity Paradise • The next year Reynolds discovered that there can be no set model of System F in which – × is interpreted as the usual binary product – → is the interpreted as the usual function space – ∀ α.τ is interpreted as a possibly restricted “large” product • This is the case no matter what notion of “parametric” is used to restrict “large” products to exclude ad hoc functions! • Reynolds proved this working in a classical set theory • In 1987, Andrew Pitts showed that set models of System F do exist in constructive set theories

  68. Problems in Parametricity Paradise • The next year Reynolds discovered that there can be no set model of System F in which – × is interpreted as the usual binary product – → is the interpreted as the usual function space – ∀ α.τ is interpreted as a possibly restricted “large” product • This is the case no matter what notion of “parametric” is used to restrict “large” products to exclude ad hoc functions! • Reynolds proved this working in a classical set theory • In 1987, Andrew Pitts showed that set models of System F do exist in constructive set theories • We won’t look at constructive set models of System F in this course

  69. Problems in Parametricity Paradise • The next year Reynolds discovered that there can be no set model of System F in which – × is interpreted as the usual binary product – → is the interpreted as the usual function space – ∀ α.τ is interpreted as a possibly restricted “large” product • This is the case no matter what notion of “parametric” is used to restrict “large” products to exclude ad hoc functions! • Reynolds proved this working in a classical set theory • In 1987, Andrew Pitts showed that set models of System F do exist in constructive set theories • We won’t look at constructive set models of System F in this course • Instead, we’ll just draw inspiration from Reynolds’ ideas

  70. The Abstraction Theorem • Formalizes uniformity of parametric polymorphism

Recommend


More recommend