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
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:
cs.appstate.edu/
∼johannp
OPLSS 2016
Topic: Reynolds’ theory of parametric polymorphism for System F Goals: - extract the fibrational essence of Reynolds’ theory
Topic: Reynolds’ theory of parametric polymorphism for System F Goals: - extract the fibrational essence of Reynolds’ theory
This is the main inspiration for the bifibrational model of para- metricity for System F we will develop
This is the main inspiration for the bifibrational model of para- metricity for System F we will develop
natural transformations
This is the main inspiration for the bifibrational model of para- metricity for System F we will develop
natural transformations
This is the main inspiration for the bifibrational model of para- metricity for System F we will develop
natural transformations
models of System F for which we can prove (bifibrational versions
This is the main inspiration for the bifibrational model of para- metricity for System F we will develop
natural transformations
models of System F for which we can prove (bifibrational versions
Set
Set
– X and Y are sets – R ⊆ (X, Y ), i.e., R ⊆ X × Y
– X and Y are sets – R ⊆ (X, Y ), i.e., R ⊆ X × Y
– f : X′ → X and g : Y ′ → Y – if (x′, y′) ∈ R′ then (fx′, gy′) ∈ R
– X and Y are sets – R ⊆ (X, Y ), i.e., R ⊆ X × Y
– f : X′ → X and g : Y ′ → Y – if (x′, y′) ∈ R′ then (fx′, gy′) ∈ R
Eq X = {(x, x) | x ∈ X}
– X and Y are sets – R ⊆ (X, Y ), i.e., R ⊆ X × Y
– f : X′ → X and g : Y ′ → Y – if (x′, y′) ∈ R′ then (fx′, gy′) ∈ R
Eq X = {(x, x) | x ∈ X}
mapping – (X, Y, R) to (X, Y ) – (f, g) to itself
mapping – (X, Y, R) to (X, Y ) – (f, g) to itself
– (f, g)∗R = {(x′, y′) ∈ (X′, Y ′) | (fx′, gy′) ∈ R} – (f, g) : (f, g)∗R → R is cartesian over (f, g)
mapping – (X, Y, R) to (X, Y ) – (f, g) to itself
– (f, g)∗R = {(x′, y′) ∈ (X′, Y ′) | (fx′, gy′) ∈ R} – (f, g) : (f, g)∗R → R is cartesian over (f, g)
(X, Y ) – Σ(f,g)R = {(fx′, gy′) ∈ (X, Y ) | (x′, y′) ∈ R′} – (f, g) : (f, g)∗R → R is opcartesian over (f, g)
mapping – (X, Y, R) to (X, Y ) – (f, g) to itself
– (f, g)∗R = {(x′, y′) ∈ (X′, Y ′) | (fx′, gy′) ∈ R} – (f, g) : (f, g)∗R → R is cartesian over (f, g)
(X, Y ) – Σ(f,g)R = {(fx′, gy′) ∈ (X, Y ) | (x′, y′) ∈ R′} – (f, g) : (f, g)∗R → R is opcartesian over (f, g)
mapping – (X, Y, R) to (X, Y ) – (f, g) to itself
– (f, g)∗R = {(x′, y′) ∈ (X′, Y ′) | (fx′, gy′) ∈ R} – (f, g) : (f, g)∗R → R is cartesian over (f, g)
(X, Y ) – Σ(f,g)R = {(fx′, gy′) ∈ (X, Y ) | (x′, y′) ∈ R′} – (f, g) : (f, g)∗R → R is opcartesian over (f, g)
The interdependence of Reynolds’ object and relational in- terpretations for types means that we don’t have two semantics, but rather a single interconnected semantics!
The interdependence of Reynolds’ object and relational in- terpretations for types means that we don’t have two semantics, but rather a single interconnected semantics!
[∆ ⊢ τ] ]rR : Rel([ [∆ ⊢ τ] ]oX, [ [∆ ⊢ τ] ]oY )
The interdependence of Reynolds’ object and relational in- terpretations for types means that we don’t have two semantics, but rather a single interconnected semantics!
[∆ ⊢ τ] ]rR : Rel([ [∆ ⊢ τ] ]oX, [ [∆ ⊢ τ] ]oY )
relations fibration on Set. Every judgement ∆ ⊢ τ induces a fibred functor [ [∆ ⊢ τ] ] : |U||∆| → U. |Rel||∆|
[ [∆⊢τ] ]r
U
[ [∆⊢τ] ]o×[ [∆⊢τ] ]o
Set × Set
The interdependence of Reynolds’ object and relational in- terpretations for types means that we don’t have two semantics, but rather a single interconnected semantics!
[∆ ⊢ τ] ]rR : Rel([ [∆ ⊢ τ] ]oX, [ [∆ ⊢ τ] ]oY )
relations fibration on Set. Every judgement ∆ ⊢ τ induces a fibred functor [ [∆ ⊢ τ] ] : |U||∆| → U. |Rel||∆|
[ [∆⊢τ] ]r
U
[ [∆⊢τ] ]o×[ [∆⊢τ] ]o
Set × Set
[∆ ⊢ τ] ] to reflect the fact that Reynolds did not give a functorial action of types on morphisms
[ [∆ ⊢ τ] ]r (Eq X1, ..., Eq X|∆|) = Eq ([ [∆ ⊢ τ] ]o(X1, ..., X|∆|))
[ [∆ ⊢ τ] ]r (Eq X1, ..., Eq X|∆|) = Eq ([ [∆ ⊢ τ] ]o(X1, ..., X|∆|))
[ [∆ ⊢ τ] ]r ◦ |Eq||∆| = Eq ◦ [ [∆ ⊢ τ] ]o |Rel||∆|
[ [∆⊢τ] ]r
Rel
|Set||∆|
|Eq||∆|
[∆⊢τ] ]o
Set
Eq
that [ [∆; Γ ⊢ t : τ] ]rR is over [ [∆; Γ ⊢ t : τ] ]oX × [ [∆; Γ ⊢ t : τ] ]oY
that [ [∆; Γ ⊢ t : τ] ]rR is over [ [∆; Γ ⊢ t : τ] ]oX × [ [∆; Γ ⊢ t : τ] ]oY
[∆ ⊢ Γ] ]oX, and B ∈ [ [∆ ⊢ Γ] ]oY . For every ∆; Γ ⊢ t : τ, if (A, B) ∈ [ [∆ ⊢ Γ] ]rR, then ([ [∆; Γ ⊢ t : τ] ]o X A, [ [∆; Γ ⊢ t : τ] ]o Y B) ∈ [ [∆ ⊢ τ] ]rR.
that [ [∆; Γ ⊢ t : τ] ]rR is over [ [∆; Γ ⊢ t : τ] ]oX × [ [∆; Γ ⊢ t : τ] ]oY
[∆ ⊢ Γ] ]oX, and B ∈ [ [∆ ⊢ Γ] ]oY . For every ∆; Γ ⊢ t : τ, if (A, B) ∈ [ [∆ ⊢ Γ] ]rR, then ([ [∆; Γ ⊢ t : τ] ]o X A, [ [∆; Γ ⊢ t : τ] ]o Y B) ∈ [ [∆ ⊢ τ] ]rR.
τ is interpreted as a fibred natural transformation ([ [∆; Γ ⊢ t : τ] ]o × [ [∆; Γ ⊢ t : τ] ]o, [ [∆; Γ ⊢ t : τ] ]r) : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ] ] |Rel||∆|
[ [Γ] ]r
[τ] ]r
[t] ]r |U||∆|
U
[ [Γ] ]o×[ [Γ] ]o
[τ] ]o×[ [τ] ]o
[t] ]o×[ [t] ]o Set × Set
[∆ ⊢ Γ] ]o and [ [∆ ⊢ τ] ]o are discrete
[∆ ⊢ Γ] ]o and [ [∆ ⊢ τ] ]o are discrete
[∆; Γ ⊢ t : τ] ]o : [ [∆ ⊢ Γ] ]o → [ [∆ ⊢ τ] ]o is a (vacuously) natural transformation
[∆ ⊢ Γ] ]o and [ [∆ ⊢ τ] ]o are discrete
[∆; Γ ⊢ t : τ] ]o : [ [∆ ⊢ Γ] ]o → [ [∆ ⊢ τ] ]o is a (vacuously) natural transformation
[∆; Γ ⊢ t : τ] ]r : [ [∆ ⊢ Γ] ]r → [ [∆ ⊢ τ] ]r is a (vacuously) natural transformation over [ [∆; Γ ⊢ t : τ] ]o × [ [∆; Γ ⊢ t : τ] ]o
[∆ ⊢ Γ] ]o and [ [∆ ⊢ τ] ]o are discrete
[∆; Γ ⊢ t : τ] ]o : [ [∆ ⊢ Γ] ]o → [ [∆ ⊢ τ] ]o is a (vacuously) natural transformation
[∆; Γ ⊢ t : τ] ]r : [ [∆ ⊢ Γ] ]r → [ [∆ ⊢ τ] ]r is a (vacuously) natural transformation over [ [∆; Γ ⊢ t : τ] ]o×[ [∆; Γ ⊢ t : τ] ]o, so each component [ [∆ ⊢ Γ] ]rR
[ [∆;Γ⊢t:τ] ]rR [
[∆ ⊢ τ] ]rR is a morphism between relations that is over [ [∆ ⊢ Γ] ]oX × [ [∆ ⊢ Γ] ]oY
[ [∆;Γ⊢t:τ] ]oX×[ [∆;Γ⊢t:τ] ]oY [
[∆ ⊢ τ] ]oX × [ [∆ ⊢ τ] ]oY
[∆ ⊢ Γ] ]o and [ [∆ ⊢ τ] ]o are discrete
[∆; Γ ⊢ t : τ] ]o : [ [∆ ⊢ Γ] ]o → [ [∆ ⊢ τ] ]o is a (vacuously) natural transformation
[∆; Γ ⊢ t : τ] ]r : [ [∆ ⊢ Γ] ]r → [ [∆ ⊢ τ] ]r is a (vacuously) natural transformation over [ [∆; Γ ⊢ t : τ] ]o×[ [∆; Γ ⊢ t : τ] ]o, so each component [ [∆ ⊢ Γ] ]rR
[ [∆;Γ⊢t:τ] ]rR [
[∆ ⊢ τ] ]rR is a morphism between relations that is over [ [∆ ⊢ Γ] ]oX × [ [∆ ⊢ Γ] ]oY
[ [∆;Γ⊢t:τ] ]oX×[ [∆;Γ⊢t:τ] ]oY [
[∆ ⊢ τ] ]oX × [ [∆ ⊢ τ] ]oY
[∆; Γ ⊢ t : τ] ]rR is a pair of morphisms ([ [∆; Γ ⊢ t : τ] ]oX, [ [∆; Γ ⊢ t : τ] ]oY ) in Set such that if (A, B) ∈ [ [∆ ⊢ Γ] ]rR, then ([ [∆; Γ ⊢ t : τ] ]o X A, [ [∆; Γ ⊢ t : τ] ]o Y B) ∈ [ [∆ ⊢ τ] ]rR
[∆ ⊢ Γ] ]o and [ [∆ ⊢ τ] ]o are discrete
[∆; Γ ⊢ t : τ] ]o : [ [∆ ⊢ Γ] ]o → [ [∆ ⊢ τ] ]o is a (vacuously) natural transformation
[∆; Γ ⊢ t : τ] ]r : [ [∆ ⊢ Γ] ]r → [ [∆ ⊢ τ] ]r is a (vacuously) natural transformation over [ [∆; Γ ⊢ t : τ] ]o×[ [∆; Γ ⊢ t : τ] ]o, so each component [ [∆ ⊢ Γ] ]rR
[ [∆;Γ⊢t:τ] ]rR [
[∆ ⊢ τ] ]rR is a morphism between relations that is over [ [∆ ⊢ Γ] ]oX × [ [∆ ⊢ Γ] ]oY
[ [∆;Γ⊢t:τ] ]oX×[ [∆;Γ⊢t:τ] ]oY [
[∆ ⊢ τ] ]oX × [ [∆ ⊢ τ] ]oY
[∆; Γ ⊢ t : τ] ]rR is a pair of morphisms ([ [∆; Γ ⊢ t : τ] ]oX, [ [∆; Γ ⊢ t : τ] ]oY ) in Set such that if (A, B) ∈ [ [∆ ⊢ Γ] ]rR, then ([ [∆; Γ ⊢ t : τ] ]o X A, [ [∆; Γ ⊢ t : τ] ]o Y B) ∈ [ [∆ ⊢ τ] ]rR
it asserts a property of [ [∆; Γ ⊢ t : τ] ]o
it asserts a property of [ [∆; Γ ⊢ t : τ] ]o
by the interpretations [ [∆; Γ ⊢ t : τ] ]r of terms as fibred natural trans- formations
it asserts a property of [ [∆; Γ ⊢ t : τ] ]o
by the interpretations [ [∆; Γ ⊢ t : τ] ]r of terms as fibred natural trans- formations
– exposes this heretofore hidden structure
it asserts a property of [ [∆; Γ ⊢ t : τ] ]o
by the interpretations [ [∆; Γ ⊢ t : τ] ]r of terms as fibred natural trans- formations
– exposes this heretofore hidden structure – opens the way to our generalization of Reynolds’ construction
it asserts a property of [ [∆; Γ ⊢ t : τ] ]o
by the interpretations [ [∆; Γ ⊢ t : τ] ]r of terms as fibred natural trans- formations
– exposes this heretofore hidden structure – opens the way to our generalization of Reynolds’ construction
[−] ]o and [ [−] ]r in such a way that the Identity Extension Lemma and the Abstraction Theorem hold, we must have sufficient structure to define analogues of all the structure we used in the rela- tions fibration on Set for more general fibrations
bration over Set by pullback, or change of base
bration over Set by pullback, or change of base
Rel(U) : Rel(E) → B × B is defined by Rel(E)
q
U
B
bration over Set by pullback, or change of base
Rel(U) : Rel(E) → B × B is defined by Rel(E)
q
U
B
bration over Set by pullback, or change of base
Rel(U) : Rel(E) → B × B is defined by Rel(E)
q
U
B
– each fibre EX of E has a terminal object KX
– each fibre EX of E has a terminal object KX – reindexing preserves terminal objects, i.e., if f : X → Y is a mor- phism in B implies f ∗KY = KX U E KX KY f ∗ B f X Y
– each fibre EX of E has a terminal object KX – reindexing preserves terminal objects, i.e., if f : X → Y is a mor- phism in B implies f ∗KY = KX U E KX KY f ∗ B f X Y
K : B → E called the truth functor for U
has products, and let δX be the diagonal morphism δX : X → X × X
has products, and let δX be the diagonal morphism δX : X → X × X
Eq : B → Rel(E) called the equality functor for Rel(U) E
U
(δX)§
ΣδX(KX)
B X
δX
X × X
has products, and let δX be the diagonal morphism δX : X → X × X
Eq : B → Rel(E) called the equality functor for Rel(U) E
U
(δX)§
ΣδX(KX)
B X
δX
X × X
has products, and let δX be the diagonal morphism δX : X → X × X
Eq : B → Rel(E) called the equality functor for Rel(U) E
U
(δX)§
ΣδX(KX)
B X
δX
X × X
relation — that acts like a characteristic function for the diagonal of X × X
has products, and let δX be the diagonal morphism δX : X → X × X
Eq : B → Rel(E) called the equality functor for Rel(U) E
U
(δX)§
ΣδX(KX)
B X
δX
X × X
relation — that acts like a characteristic function for the diagonal of X × X
{(x, x) | x ∈ X} when instantiated to the relations fibration on Set
{(x, x) | x ∈ X} when instantiated to the relations fibration on Set
{(x, x) | x ∈ X} when instantiated to the relations fibration on Set
Counterexample: Eq for Id : Set → Set
{(x, x) | x ∈ X} when instantiated to the relations fibration on Set
Counterexample: Eq for Id : Set → Set
{(x, x) | x ∈ X} when instantiated to the relations fibration on Set
Counterexample: Eq for Id : Set → Set
need to be able to opreindex along arbitrary morphisms
{(x, x) | x ∈ X} when instantiated to the relations fibration on Set
Counterexample: Eq for Id : Set → Set
need to be able to opreindex along arbitrary morphisms
algebras in parametric models, in the paper we need that Eq is full
{(x, x) | x ∈ X} when instantiated to the relations fibration on Set
Counterexample: Eq for Id : Set → Set
need to be able to opreindex along arbitrary morphisms
algebras in parametric models, in the paper we need that Eq is full
such fibred functors
such fibred functors
IEL and the Abstraction Theorem hold
such fibred functors
IEL and the Abstraction Theorem hold
such fibred functors
IEL and the Abstraction Theorem hold
fibrations
– Reynolds’ definitions of [ [∆ ⊢ τ1 → τ2] ]o and [ [∆ ⊢ τ1 → τ2] ]r are derived from the cartesian closed structure of Set and Rel
– Reynolds’ definitions of [ [∆ ⊢ τ1 → τ2] ]o and [ [∆ ⊢ τ1 → τ2] ]r are derived from the cartesian closed structure of Set and Rel – U : Rel → Set × Set preserves the cartesian closed structure
– Reynolds’ definitions of [ [∆ ⊢ τ1 → τ2] ]o and [ [∆ ⊢ τ1 → τ2] ]r are derived from the cartesian closed structure of Set and Rel – U : Rel → Set × Set preserves the cartesian closed structure – Thus [ [∆; Γ ⊢ t : τ] ]r is over [ [∆; Γ ⊢ t : τ] ]o × [ [∆; Γ ⊢ t : τ] ]o as required by the Abstraction Theorem
– Reynolds’ definitions of [ [∆ ⊢ τ1 → τ2] ]o and [ [∆ ⊢ τ1 → τ2] ]r are derived from the cartesian closed structure of Set and Rel – U : Rel → Set × Set preserves the cartesian closed structure – Thus [ [∆; Γ ⊢ t : τ] ]r is over [ [∆; Γ ⊢ t : τ] ]o × [ [∆; Γ ⊢ t : τ] ]o as required by the Abstraction Theorem
that the Abstraction Theorem holds — by a fibration U : E → B if
– Reynolds’ definitions of [ [∆ ⊢ τ1 → τ2] ]o and [ [∆ ⊢ τ1 → τ2] ]r are derived from the cartesian closed structure of Set and Rel – U : Rel → Set × Set preserves the cartesian closed structure – Thus [ [∆; Γ ⊢ t : τ] ]r is over [ [∆; Γ ⊢ t : τ] ]o × [ [∆; Γ ⊢ t : τ] ]o as required by the Abstraction Theorem
that the Abstraction Theorem holds — by a fibration U : E → B if – E and B are cartesian closed categories
– Reynolds’ definitions of [ [∆ ⊢ τ1 → τ2] ]o and [ [∆ ⊢ τ1 → τ2] ]r are derived from the cartesian closed structure of Set and Rel – U : Rel → Set × Set preserves the cartesian closed structure – Thus [ [∆; Γ ⊢ t : τ] ]r is over [ [∆; Γ ⊢ t : τ] ]o × [ [∆; Γ ⊢ t : τ] ]o as required by the Abstraction Theorem
that the Abstraction Theorem holds — by a fibration U : E → B if – E and B are cartesian closed categories – U preserves the cartesian closed structure
– E and B are cartesian closed – U preserves the cartesian closed structure
– E and B are cartesian closed – U preserves the cartesian closed structure
arrow fibration if
– E and B are cartesian closed – U preserves the cartesian closed structure
arrow fibration if – Rel(U) is an arrow fibration
– E and B are cartesian closed – U preserves the cartesian closed structure
arrow fibration if – Rel(U) is an arrow fibration – for all X and Y in B Eq (X ⇒ Y ) ∼ = (Eq X ⇒ Eq Y )
– E and B are cartesian closed – U preserves the cartesian closed structure
arrow fibration if – Rel(U) is an arrow fibration – for all X and Y in B Eq (X ⇒ Y ) ∼ = (Eq X ⇒ Eq Y )
serving arrow fibration (see MFPS’15 and FoSSaCS’16)
ing ∀ as right adjoint to weakening by a type variable
ing ∀ as right adjoint to weakening by a type variable
another on the total category, and then try to link these adjoints
ing ∀ as right adjoint to weakening by a type variable
another on the total category, and then try to link these adjoints
functions, not just the parametrically polymorphic ones!
ing ∀ as right adjoint to weakening by a type variable
another on the total category, and then try to link these adjoints
functions, not just the parametrically polymorphic ones!
ing ∀ as right adjoint to weakening by a type variable
another on the total category, and then try to link these adjoints
functions, not just the parametrically polymorphic ones!
ing ∀ as right adjoint to weakening by a type variable
another on the total category, and then try to link these adjoints
functions, not just the parametrically polymorphic ones!
– Objects: equality preserving fibred functors from |Rel(U)|n to Rel(U)
ing ∀ as right adjoint to weakening by a type variable
another on the total category, and then try to link these adjoints
functions, not just the parametrically polymorphic ones!
– Objects: equality preserving fibred functors from |Rel(U)|n to Rel(U) – Morphisms: fibred natural transformations between them
ing ∀ as right adjoint to weakening by a type variable
another on the total category, and then try to link these adjoints
functions, not just the parametrically polymorphic ones!
– Objects: equality preserving fibred functors from |Rel(U)|n to Rel(U) – Morphisms: fibred natural transformations between them
– for every projection πn : |Rel(U)|n+1 → |Rel(U)|n, the functor
has a right adjoint ∀n
– for every projection πn : |Rel(U)|n+1 → |Rel(U)|n, the functor
has a right adjoint ∀n – this family of adjunctions is natural in n
– for every projection πn : |Rel(U)|n+1 → |Rel(U)|n, the functor
has a right adjoint ∀n – this family of adjunctions is natural in n
there is an isomorphism ϕn : Hom(F ◦ πn, G) ∼ = Hom(F, ∀G) that is natural in n
and ∀-fibrations to interpret System F types as fibred functors and System F terms as fibred natural transformations
berg, and F. Orsanigo. WadlerFest’16.