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
tional parametric model of System F
tional parametric model of System F
that are both equality preserving arrow fibrations and ∀-fibrations to interpret System F
tional parametric model of System F
that are both equality preserving arrow fibrations and ∀-fibrations to interpret System F – types as fibred functors
tional parametric model of System F
that are both equality preserving arrow fibrations and ∀-fibrations to interpret System F – types as fibred functors – terms as fibred natural transformations
tional parametric model of System F
that are both equality preserving arrow fibrations and ∀-fibrations to interpret System F – types as fibred functors – terms as fibred natural transformations
tional parametric model of System F
that are both equality preserving arrow fibrations and ∀-fibrations to interpret System F – types as fibred functors – terms as fibred natural transformations
∀-fibration
[ [∆ ⊢ τ] ] : |Rel(U)||∆| → Rel(U) by
[ [∆ ⊢ τ] ] : |Rel(U)||∆| → Rel(U) by – Type variables: [ [∆ ⊢ αi] ]oX = Xi and [ [∆ ⊢ αi] ]rR = Ri
[ [∆ ⊢ τ] ] : |Rel(U)||∆| → Rel(U) by – Type variables: [ [∆ ⊢ αi] ]oX = Xi and [ [∆ ⊢ αi] ]rR = Ri – Arrow types: [ [∆ ⊢ τ1 → τ2] ] = [ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ]
[ [∆ ⊢ τ] ] : |Rel(U)||∆| → Rel(U) by – Type variables: [ [∆ ⊢ αi] ]oX = Xi and [ [∆ ⊢ αi] ]rR = Ri – Arrow types: [ [∆ ⊢ τ1 → τ2] ] = [ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ] – Forall types: [ [∆ ⊢ ∀α.τ] ] = ∀[ [∆, α ⊢ τ] ]
[ [∆ ⊢ τ] ] : |Rel(U)||∆| → Rel(U) by – Type variables: [ [∆ ⊢ αi] ]oX = Xi and [ [∆ ⊢ αi] ]rR = Ri – Arrow types: [ [∆ ⊢ τ1 → τ2] ] = [ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ] – Forall types: [ [∆ ⊢ ∀α.τ] ] = ∀[ [∆, α ⊢ τ] ]
[∆ ⊢ τ] ] on morphisms is needed because the domain
[∆ ⊢ τ] ] is discrete
preserving fibred functor
preserving fibred functor
preserving fibred functor
[∆ ⊢ τ] ] = ∀[ [∆, α ⊢ τ ′] ] is an equality preserving fibred functor whenever [ [∆, α ⊢ τ ′] ] is, just by the definition of ∀ : (|Rel(U)|n+1 →Eq Rel(U)) → (|Rel(U)|n →Eq Rel(U))
preserving fibred functor
[∆ ⊢ τ] ] = ∀[ [∆, α ⊢ τ ′] ] is an equality preserving fibred functor whenever [ [∆, α ⊢ τ ′] ] is, just by the definition of ∀ : (|Rel(U)|n+1 →Eq Rel(U)) → (|Rel(U)|n →Eq Rel(U))
equality preserving then so is ∀F
preserving fibred functor
[∆ ⊢ τ] ] = ∀[ [∆, α ⊢ τ ′] ] is an equality preserving fibred functor whenever [ [∆, α ⊢ τ ′] ] is, just by the definition of ∀ : (|Rel(U)|n+1 →Eq Rel(U)) → (|Rel(U)|n →Eq Rel(U))
equality preserving then so is ∀F
pretation of types, rather than something to be proved post facto
preserving fibred functor
[∆ ⊢ τ] ] = ∀[ [∆, α ⊢ τ ′] ] is an equality preserving fibred functor whenever [ [∆, α ⊢ τ ′] ] is, just by the definition of ∀ : (|Rel(U)|n+1 →Eq Rel(U)) → (|Rel(U)|n →Eq Rel(U))
equality preserving then so is ∀F
pretation of types, rather than something to be proved post facto
in terms of more basic concepts using opfibrational structure of U
phism λ : Hom(W × X, Y ) ∼ = Hom(W, X ⇒ Y ) that is natural in W
phism λ : Hom(W × X, Y ) ∼ = Hom(W, X ⇒ Y ) that is natural in W
evX,Y = λ−1(id X⇒Y ) : (X ⇒ Y ) × X → Y
phism λ : Hom(W × X, Y ) ∼ = Hom(W, X ⇒ Y ) that is natural in W
evX,Y = λ−1(id X⇒Y ) : (X ⇒ Y ) × X → Y
ϕn : Hom(F ◦ πn, G) ∼ = Hom(F, ∀nG) that are natural in n
Define fibred natural transformations [ [∆; Γ ⊢ t : τ] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ] ] by
Define fibred natural transformations [ [∆; Γ ⊢ t : τ] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ] ] by
∆ ⊢ τi xi : τi ∈ Γ ∆; Γ ⊢ xi : τi then [ [∆; Γ ⊢ xi : τi] ] = πi
Define fibred natural transformations [ [∆; Γ ⊢ t : τ] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ] ] by
∆ ⊢ τi xi : τi ∈ Γ ∆; Γ ⊢ xi : τi then [ [∆; Γ ⊢ xi : τi] ] = πi
Define fibred natural transformations [ [∆; Γ ⊢ t : τ] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ] ] by
∆ ⊢ τi xi : τi ∈ Γ ∆; Γ ⊢ xi : τi then [ [∆; Γ ⊢ xi : τi] ] = πi
∆; Γ, x : τ1 ⊢ t : τ2 ∆; Γ ⊢ λx.t : τ1 → τ2 then [ [∆; Γ ⊢ λx.t : τ1 → τ2] ] : [ [∆ ⊢ Γ] ] → ([ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ]) [ [∆; Γ ⊢ λx.t : τ1 → τ2] ] = λ[ [∆; Γ, x : τ1 ⊢ t : τ2] ]
∆; Γ, x : τ1 ⊢ t : τ2 ∆; Γ ⊢ λx.t : τ1 → τ2 then [ [∆; Γ ⊢ λx.t : τ1 → τ2] ] : [ [∆ ⊢ Γ] ] → ([ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ]) [ [∆; Γ ⊢ λx.t : τ1 → τ2] ] = λ[ [∆; Γ, x : τ1 ⊢ t : τ2] ]
[ [∆; Γ, x : τ1 ⊢ t : τ2] ] : [ [∆ ⊢ Γ] ] × [ [∆ ⊢ τ1] ] → [ [∆ ⊢ τ2] ]
∆; Γ, x : τ1 ⊢ t : τ2 ∆; Γ ⊢ λx.t : τ1 → τ2 then [ [∆; Γ ⊢ λx.t : τ1 → τ2] ] : [ [∆ ⊢ Γ] ] → ([ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ]) [ [∆; Γ ⊢ λx.t : τ1 → τ2] ] = λ[ [∆; Γ, x : τ1 ⊢ t : τ2] ]
[ [∆; Γ, x : τ1 ⊢ t : τ2] ] : [ [∆ ⊢ Γ] ] × [ [∆ ⊢ τ1] ] → [ [∆ ⊢ τ2] ]
∆; Γ, x : τ1 ⊢ t : τ2 ∆; Γ ⊢ λx.t : τ1 → τ2 then [ [∆; Γ ⊢ λx.t : τ1 → τ2] ] : [ [∆ ⊢ Γ] ] → ([ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ]) [ [∆; Γ ⊢ λx.t : τ1 → τ2] ] = λ[ [∆; Γ, x : τ1 ⊢ t : τ2] ]
[ [∆; Γ, x : τ1 ⊢ t : τ2] ] : [ [∆ ⊢ Γ] ] × [ [∆ ⊢ τ1] ] → [ [∆ ⊢ τ2] ]
∆; Γ ⊢ t1 : τ1 ∆; Γ ⊢ t2 : τ1 → τ2 ∆; Γ ⊢ t2t1 : τ2 then [ [∆; Γ ⊢ t2t1 : τ2] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ2] ] [ [∆; Γ ⊢ t2t1 : τ2] ] = evτ1,τ2 ◦ [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ]
∆; Γ ⊢ t1 : τ1 ∆; Γ ⊢ t2 : τ1 → τ2 ∆; Γ ⊢ t2t1 : τ2 then [ [∆; Γ ⊢ t2t1 : τ2] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ2] ] [ [∆; Γ ⊢ t2t1 : τ2] ] = evτ1,τ2 ◦ [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ]
[ [∆; Γ ⊢ t1 : τ1] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ1] ]
∆; Γ ⊢ t1 : τ1 ∆; Γ ⊢ t2 : τ1 → τ2 ∆; Γ ⊢ t2t1 : τ2 then [ [∆; Γ ⊢ t2t1 : τ2] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ2] ] [ [∆; Γ ⊢ t2t1 : τ2] ] = evτ1,τ2 ◦ [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ]
[ [∆; Γ ⊢ t1 : τ1] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ1] ] [ [∆; Γ ⊢ t2 : τ1 → τ2] ] : [ [∆ ⊢ Γ] ] → ([ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ])
∆; Γ ⊢ t1 : τ1 ∆; Γ ⊢ t2 : τ1 → τ2 ∆; Γ ⊢ t2t1 : τ2 then [ [∆; Γ ⊢ t2t1 : τ2] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ2] ] [ [∆; Γ ⊢ t2t1 : τ2] ] = evτ1,τ2 ◦ [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ]
[ [∆; Γ ⊢ t1 : τ1] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ1] ] [ [∆; Γ ⊢ t2 : τ1 → τ2] ] : [ [∆ ⊢ Γ] ] → ([ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ]) [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ] : [ [Γ] ] → ([ [τ1] ] ⇒ [ [τ2] ]) × [ [τ1] ]
∆; Γ ⊢ t1 : τ1 ∆; Γ ⊢ t2 : τ1 → τ2 ∆; Γ ⊢ t2t1 : τ2 then [ [∆; Γ ⊢ t2t1 : τ2] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ2] ] [ [∆; Γ ⊢ t2t1 : τ2] ] = evτ1,τ2 ◦ [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ]
[ [∆; Γ ⊢ t1 : τ1] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ1] ] [ [∆; Γ ⊢ t2 : τ1 → τ2] ] : [ [∆ ⊢ Γ] ] → ([ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ]) [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ] : [ [Γ] ] → ([ [τ1] ] ⇒ [ [τ2] ]) × [ [τ1] ]
∆; Γ ⊢ t1 : τ1 ∆; Γ ⊢ t2 : τ1 → τ2 ∆; Γ ⊢ t2t1 : τ2 then [ [∆; Γ ⊢ t2t1 : τ2] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ2] ] [ [∆; Γ ⊢ t2t1 : τ2] ] = evτ1,τ2 ◦ [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ]
[ [∆; Γ ⊢ t1 : τ1] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ1] ] [ [∆; Γ ⊢ t2 : τ1 → τ2] ] : [ [∆ ⊢ Γ] ] → ([ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ]) [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ] : [ [Γ] ] → ([ [τ1] ] ⇒ [ [τ2] ]) × [ [τ1] ]
∆, α; Γ ⊢ t : τ ∆; Γ ⊢ Λα.t : ∀α.τ then [ [∆; Γ ⊢ Λα.t : ∀α.τ] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ ∀α.τ] ] = [ [∆ ⊢ Γ] ] → ∀[ [∆, α ⊢ τ] ] [ [∆; Γ ⊢ Λα.t : ∀α.τ] ] = ϕ|∆|[ [∆, α; Γ ⊢ t : τ] ]
[ [∆, α; Γ ⊢ t : τ] ] : [ [∆, α ⊢ Γ] ] → [ [∆, α ⊢ τ] ] = [ [∆ ⊢ Γ] ] ◦ π|∆| → [ [∆, α ⊢ τ] ]
∆; Γ ⊢ t : ∀α.τ2 ∆ ⊢ τ1 ∆; Γ ⊢ t τ1 : τ2[α → τ1] then [ [∆; Γ ⊢ t τ1 : τ2[α → τ1]] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ2[α → τ1]] ] [ [∆; Γ ⊢ t τ1 : τ2[α → τ1]] ] = ϕ−1
|∆|[
[∆; Γ ⊢ t : ∀α.τ2] ] ◦ id |∆|, [ [∆ ⊢ τ1] ]
[ [∆; Γ ⊢ t : ∀α.τ2] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ ∀α.τ2] ] = [ [∆ ⊢ Γ] ] → ∀[ [∆, α ⊢ τ2] ]
[∆; Γ ⊢ (Λα.t)τ1 : τ2[α → τ1]] ] = [ [∆; Γ ⊢ t[α → τ1] : τ2[α → τ1]] ]
[∆; Γ ⊢ t : ∀β.τ] ] = [ [∆; Γ ⊢ Λα.t α : ∀β.τ] ]
[∆; Γ ⊢ (Λα.t)τ1 : τ2[α → τ1]] ] = [ [∆; Γ ⊢ t[α → τ1] : τ2[α → τ1]] ]
[∆; Γ ⊢ t : ∀β.τ] ] = [ [∆; Γ ⊢ Λα.t α : ∀β.τ] ]
[∆; Γ ⊢ (λx.t2)t1 : τ2] ] = [ [∆; Γ ⊢ t2[x → t1] : τ2] ]
[∆; Γ ⊢ t : τ1 → τ2] ] = [ [∆; Γ ⊢ λx.tx : τ1 → τ2] ]
∀-fibration, then there is a λ2-fibration in which types ∆ ⊢ τ are inter- preted as equality preserving fibred functors [ [∆ ⊢ τ] ] : |Rel(U)||∆| →Eq Rel(U) and terms ∆; Γ ⊢ t : τ are interpreted as fibred natural trans- formations [ [∆; Γ ⊢ t : τ] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ] ]
∀-fibration, then there is a λ2-fibration in which types ∆ ⊢ τ are inter- preted as equality preserving fibred functors [ [∆ ⊢ τ] ] : |Rel(U)||∆| →Eq Rel(U) and terms ∆; Γ ⊢ t : τ are interpreted as fibred natural trans- formations [ [∆; Γ ⊢ t : τ] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ] ] |Rel(E)||∆|
[ [Γ] ]r
[τ] ]r
[t] ]r |Rel(U)||∆|
U
[ [Γ] ]o×[ [Γ] ]o
[τ] ]o×[ [τ] ]o
[t] ]o×[ [t] ]o B × B
In particular, for every fibration U : E → B whose relations fibration is an equality preserving arrow fibration and a forall fibration, for every System F type ∆ ⊢ τ and term ∆; Γ ⊢ t : τ, we get:
In particular, for every fibration U : E → B whose relations fibration is an equality preserving arrow fibration and a forall fibration, for every System F type ∆ ⊢ τ and term ∆; Γ ⊢ t : τ, we get:
[∆ ⊢ τ] ]o : |B||∆| → B
In particular, for every fibration U : E → B whose relations fibration is an equality preserving arrow fibration and a forall fibration, for every System F type ∆ ⊢ τ and term ∆; Γ ⊢ t : τ, we get:
[∆ ⊢ τ] ]o : |B||∆| → B
[∆ ⊢ τ] ]r : |Rel(E)||∆| → Rel(E)
In particular, for every fibration U : E → B whose relations fibration is an equality preserving arrow fibration and a forall fibration, for every System F type ∆ ⊢ τ and term ∆; Γ ⊢ t : τ, we get:
[∆ ⊢ τ] ]o : |B||∆| → B
[∆ ⊢ τ] ]r : |Rel(E)||∆| → Rel(E)
i.e., a proof that [ [∆ ⊢ τ] ] is equality preserving
In particular, for every fibration U : E → B whose relations fibration is an equality preserving arrow fibration and a forall fibration, for every System F type ∆ ⊢ τ and term ∆; Γ ⊢ t : τ, we get:
[∆ ⊢ τ] ]o : |B||∆| → B
[∆ ⊢ τ] ]r : |Rel(E)||∆| → Rel(E)
i.e., a proof that [ [∆ ⊢ τ] ] is equality preserving
[ [∆; Γ ⊢ t : τ] ]o : [ [∆ ⊢ Γ] ]o → [ [∆ ⊢ τ] ]o
In particular, for every fibration U : E → B whose relations fibration is an equality preserving arrow fibration and a forall fibration, for every System F type ∆ ⊢ τ and term ∆; Γ ⊢ t : τ, we get:
[∆ ⊢ τ] ]o : |B||∆| → B
[∆ ⊢ τ] ]r : |Rel(E)||∆| → Rel(E)
i.e., a proof that [ [∆ ⊢ τ] ] is equality preserving
[ [∆; Γ ⊢ t : τ] ]o : [ [∆ ⊢ Γ] ]o → [ [∆ ⊢ τ] ]o
a proof that ∆; Γ ⊢ t : τ has a relational interpretation as a natural transformation [ [∆; Γ ⊢ t : τ] ]r : [ [∆ ⊢ Γ] ]r → [ [∆ ⊢ τ] ]r over [ [∆; Γ ⊢ t : τ] ]o × [ [∆; Γ ⊢ t : τ] ]o.
internal language for our model
internal language for our model
internal language for our model
internal language for our model
– our model has initial algebras for strong functors
internal language for our model
– our model has initial algebras for strong functors – our model has final coalgebras for strong functors
internal language for our model
– our model has initial algebras for strong functors – our model has final coalgebras for strong functors – parametricity implies dinaturality
internal language for our model
– our model has initial algebras for strong functors – our model has final coalgebras for strong functors – parametricity implies dinaturality
categories, functors, and natural transformations
categories, functors, and natural transformations with a semantics based on fibrations, fibred functors, and fibred natural transformations
categories, functors, and natural transformations with a semantics based on fibrations, fibred functors, and fibred natural transformations
tions with impredicative Set
tions with impredicative Set
tions with impredicative Set
tions with impredicative Set
instance of our framework that models ad hoc polymorphism...
tions with impredicative Set
instance of our framework that models ad hoc polymorphism...
an instance of our framework via the relations fibration on Set
tions with impredicative Set
instance of our framework that models ad hoc polymorphism...
an instance of our framework via the relations fibration on Set
are understood as internal to the category of ω-sets)
flavors – changing the base category of the fibration changes the object model used to interpret types and terms
flavors – changing the base category of the fibration changes the object model used to interpret types and terms – changing the total category and the fibration (i.e., the functor itself) changes the notion of relational logic
flavors – changing the base category of the fibration changes the object model used to interpret types and terms – changing the total category and the fibration (i.e., the functor itself) changes the notion of relational logic
valued parametricity” over a constructively completely distributive complete non-trivial lattice of truth values
Orsanigo showed how to avoid baking the IEL into our framework, but rather derive it from more primitive assumptions about equality- preserving cones that can be used to interpret forall types
Orsanigo showed how to avoid baking the IEL into our framework, but rather derive it from more primitive assumptions about equality- preserving cones that can be used to interpret forall types
son showed how comprehension for U can be used to ensure that Rel(U) is an equality preserving arrow fibration [This paper won the best the-
Orsanigo showed how to avoid baking the IEL into our framework, but rather derive it from more primitive assumptions about equality- preserving cones that can be used to interpret forall types
son showed how comprehension for U can be used to ensure that Rel(U) is an equality preserving arrow fibration [This paper won the best the-
Orsanigo developed a proof-relevant version of our framework
Orsanigo showed how to avoid baking the IEL into our framework, but rather derive it from more primitive assumptions about equality- preserving cones that can be used to interpret forall types
son showed how comprehension for U can be used to ensure that Rel(U) is an equality preserving arrow fibration [This paper won the best the-
Orsanigo developed a proof-relevant version of our framework
ement Aubert, Fredrik Nordvall Forsberg, and I are working on ex- tending our framework to a polymorphic calculus with computational effects (System F with effect-free constants and algebraic operations in the style of Plotkin and Power’s effectful simply-typed calculus λc)
E.S. Bainbridge, P.J. Freyd, A. Scedrov, and P. Scott. Theoretical Computer Science, 1990. [Gives a functorial semantics of polymorphism]
parametric polymorphism (PL-categories)]
Birkedal and R. Møgelberg. Mathematical Structures in Computer Science, 2005. [Constructs sophisticated models of parametricity and its logical structure. Also argues that not all expected consequences hold in Ma and Reynolds’ framework]
to mix fibrations with reflexive graphs, but obtains existence of initial algebras only for strictly positive functors]