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
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 }
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
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 ]
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 Γ
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
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 : ∀ α.τ ( ξ Λ )
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 : τ
Reynolds’ Semantics of Types - The Set Up • Reynolds defines two “parallel” semantics for System F types ∆ ⊢ τ
Reynolds’ Semantics of Types - The Set Up • Reynolds defines two “parallel” semantics for System F types ∆ ⊢ τ ] o : Set | ∆ | → Set – an object semantics [ [∆ ⊢ τ ]
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 [ [∆ ⊢ τ ]
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 )
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 }
Reynolds’ Semantics of Types • Type variables: [ [∆ ⊢ α i ] ] o X = X i and [ [∆ ⊢ α i ] ] r R = R i
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
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 }
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
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 ′ ) } [∆ , α ⊢ τ ]
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 ′ ) } − [ [∆ ⊢ ∀ α.τ ] [∆ , α ⊢ τ ]
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
Some Observations • By construction, relational interpretations of functions (on types and on terms) map related inputs to related outputs
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 )
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:
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
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
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
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!
Identity Extension Lemma • Key for many applications of parametricity
Identity Extension Lemma • Key for many applications of parametricity • Intuitively, relational interpretations of types preserve equality
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 | ∆ | ))
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
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
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
Reynolds’ Semantics of Terms - variables • If ∆; Γ ⊢ x i : τ i then [ [∆; Γ ⊢ x i : τ i ] ] o X A = A i
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
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
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 )
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
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
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 )
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
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
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
Taking Stock • So far, term interpretations are all in the required sets
Taking Stock • So far, term interpretations are all in the required sets • But when Reynolds interpreted type abstractions and applications
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
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
Reynolds’ Semantics of Terms - type abstractions • If ∆ , α ; Γ ⊢ t : τ ∆; Γ ⊢ Λ α.t : ∀ α.τ then [ [∆; Γ ⊢ Λ α.t : ∀ α.τ ] ] o X A = Π S : Set [ [∆ , α ; Γ ⊢ t : τ ] ] o ( X, S ) A
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 ) | ... }
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 )
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...
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 )
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
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 ) | ... }
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
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...
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
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 ∀ α.τ !
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!
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?
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
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
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
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
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!
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
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
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
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
The Abstraction Theorem • Formalizes uniformity of parametric polymorphism
Recommend
More recommend