Reynolds Parametricity Patricia Johann Appalachian State University - - PowerPoint PPT Presentation

reynolds parametricity
SMART_READER_LITE
LIVE PREVIEW

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:


slide-1
SLIDE 1

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

slide-2
SLIDE 2

Course Outline

Topic: Reynolds’ theory of parametric polymorphism for System F Goals: - extract the fibrational essence of Reynolds’ theory

  • generalize Reynolds’ construction to very general models
  • Lecture 1: Reynolds’ theory of parametricity for System F
  • Lecture 2: Introduction to fibrations
  • Lecture 3: A bifibrational view of parametricity
  • Lecture 4: Bifibrational parametric models for System F
slide-3
SLIDE 3

Course Outline

Topic: Reynolds’ theory of parametric polymorphism for System F Goals: - extract the fibrational essence of Reynolds’ theory

  • generalize Reynolds’ construction to very general models
  • Lecture 1: Reynolds’ theory of parametricity for System F
  • Lecture 2: Introduction to fibrations
  • Lecture 3: A bifibrational view of parametricity
  • Lecture 4: Bifibrational parametric models for System F
slide-4
SLIDE 4

Where Were We?

  • In Lecture 1 we recalled Reynolds’ standard relational parametricity

This is the main inspiration for the bifibrational model of para- metricity for System F we will develop

slide-5
SLIDE 5

Where Were We?

  • In Lecture 1 we recalled Reynolds’ standard relational parametricity

This is the main inspiration for the bifibrational model of para- metricity for System F we will develop

  • Last time we had an introduction to bifibrations, fibred functors, fibred

natural transformations

slide-6
SLIDE 6

Where Were We?

  • In Lecture 1 we recalled Reynolds’ standard relational parametricity

This is the main inspiration for the bifibrational model of para- metricity for System F we will develop

  • Last time we had an introduction to bifibrations, fibred functors, fibred

natural transformations

  • Today we’ll view Reynolds’ construction and results through the lens
  • f the relations (bi)fibration on Set
slide-7
SLIDE 7

Where Were We?

  • In Lecture 1 we recalled Reynolds’ standard relational parametricity

This is the main inspiration for the bifibrational model of para- metricity for System F we will develop

  • Last time we had an introduction to bifibrations, fibred functors, fibred

natural transformations

  • Today we’ll view Reynolds’ construction and results through the lens
  • f the relations (bi)fibration on Set
  • Next time we’ll generalize Reynolds’ constructions to bifibrational

models of System F for which we can prove (bifibrational versions

  • f) the IEL and Abstraction Theorem
slide-8
SLIDE 8

Where Were We?

  • In Lecture 1 we recalled Reynolds’ standard relational parametricity

This is the main inspiration for the bifibrational model of para- metricity for System F we will develop

  • Last time we had an introduction to bifibrations, fibred functors, fibred

natural transformations

  • Today we’ll view Reynolds’ construction and results through the lens
  • f the relations (bi)fibration on Set
  • Next time we’ll generalize Reynolds’ constructions to bifibrational

models of System F for which we can prove (bifibrational versions

  • f) the IEL and Abstraction Theorem
  • Reynolds’ construction is (ignoring size issues) such a model
slide-9
SLIDE 9

Plan for Today

  • Introduce the the relations fibration on Set
slide-10
SLIDE 10

Plan for Today

  • Introduce the the relations fibration on Set
  • Recall Reynolds’ (attempted) model of parametricity for System F as
  • riginally formulated — with no fibrations in sight
slide-11
SLIDE 11

Plan for Today

  • Introduce the the relations fibration on Set
  • Recall Reynolds’ (attempted) model of parametricity for System F as
  • riginally formulated — with no fibrations in sight
  • Re-state Reynolds’ construction in terms of the relations fibration on

Set

slide-12
SLIDE 12

Plan for Today

  • Introduce the the relations fibration on Set
  • Recall Reynolds’ (attempted) model of parametricity for System F as
  • riginally formulated — with no fibrations in sight
  • Re-state Reynolds’ construction in terms of the relations fibration on

Set

  • Set up infrastructure needed for our generalization
slide-13
SLIDE 13

The Category Rel

  • An object of Rel is a triple (X, Y, R)

– X and Y are sets – R ⊆ (X, Y ), i.e., R ⊆ X × Y

slide-14
SLIDE 14

The Category Rel

  • An object of Rel is a triple (X, Y, R)

– X and Y are sets – R ⊆ (X, Y ), i.e., R ⊆ X × Y

  • A morphism (X′, Y ′, R′) → (X, Y, R) is a pair (f, g)

– f : X′ → X and g : Y ′ → Y – if (x′, y′) ∈ R′ then (fx′, gy′) ∈ R

slide-15
SLIDE 15

The Category Rel

  • An object of Rel is a triple (X, Y, R)

– X and Y are sets – R ⊆ (X, Y ), i.e., R ⊆ X × Y

  • A morphism (X′, Y ′, R′) → (X, Y, R) is a pair (f, g)

– f : X′ → X and g : Y ′ → Y – if (x′, y′) ∈ R′ then (fx′, gy′) ∈ R

  • Each set X has an equality relation

Eq X = {(x, x) | x ∈ X}

slide-16
SLIDE 16

The Category Rel

  • An object of Rel is a triple (X, Y, R)

– X and Y are sets – R ⊆ (X, Y ), i.e., R ⊆ X × Y

  • A morphism (X′, Y ′, R′) → (X, Y, R) is a pair (f, g)

– f : X′ → X and g : Y ′ → Y – if (x′, y′) ∈ R′ then (fx′, gy′) ∈ R

  • Each set X has an equality relation

Eq X = {(x, x) | x ∈ X}

  • This can be extended to an equality functor from Set to Rel in the
  • bvious way
slide-17
SLIDE 17

The Relations Fibration on Set

  • The relations fibration on Set is the functor U : Rel → Set × Set

mapping – (X, Y, R) to (X, Y ) – (f, g) to itself

slide-18
SLIDE 18

The Relations Fibration on Set

  • The relations fibration on Set is the functor U : Rel → Set × Set

mapping – (X, Y, R) to (X, Y ) – (f, g) to itself

  • U is a fibration: For R, UR = (X, Y ), and (f, g) : (X′, Y ′) → (X, Y )

– (f, g)∗R = {(x′, y′) ∈ (X′, Y ′) | (fx′, gy′) ∈ R} – (f, g) : (f, g)∗R → R is cartesian over (f, g)

slide-19
SLIDE 19

The Relations Fibration on Set

  • The relations fibration on Set is the functor U : Rel → Set × Set

mapping – (X, Y, R) to (X, Y ) – (f, g) to itself

  • U is a fibration: For R, UR = (X, Y ), and (f, g) : (X′, Y ′) → (X, Y )

– (f, g)∗R = {(x′, y′) ∈ (X′, Y ′) | (fx′, gy′) ∈ R} – (f, g) : (f, g)∗R → R is cartesian over (f, g)

  • U is an opfibration: For R, UR = (X′, Y ′), and (f, g) : (X′, Y ′) →

(X, Y ) – Σ(f,g)R = {(fx′, gy′) ∈ (X, Y ) | (x′, y′) ∈ R′} – (f, g) : (f, g)∗R → R is opcartesian over (f, g)

slide-20
SLIDE 20

The Relations Fibration on Set

  • The relations fibration on Set is the functor U : Rel → Set × Set

mapping – (X, Y, R) to (X, Y ) – (f, g) to itself

  • U is a fibration: For R, UR = (X, Y ), and (f, g) : (X′, Y ′) → (X, Y )

– (f, g)∗R = {(x′, y′) ∈ (X′, Y ′) | (fx′, gy′) ∈ R} – (f, g) : (f, g)∗R → R is cartesian over (f, g)

  • U is an opfibration: For R, UR = (X′, Y ′), and (f, g) : (X′, Y ′) →

(X, Y ) – Σ(f,g)R = {(fx′, gy′) ∈ (X, Y ) | (x′, y′) ∈ R′} – (f, g) : (f, g)∗R → R is opcartesian over (f, g)

  • U is (thus) a bifibration
slide-21
SLIDE 21

The Relations Fibration on Set

  • The relations fibration on Set is the functor U : Rel → Set × Set

mapping – (X, Y, R) to (X, Y ) – (f, g) to itself

  • U is a fibration: For R, UR = (X, Y ), and (f, g) : (X′, Y ′) → (X, Y )

– (f, g)∗R = {(x′, y′) ∈ (X′, Y ′) | (fx′, gy′) ∈ R} – (f, g) : (f, g)∗R → R is cartesian over (f, g)

  • U is an opfibration: For R, UR = (X′, Y ′), and (f, g) : (X′, Y ′) →

(X, Y ) – Σ(f,g)R = {(fx′, gy′) ∈ (X, Y ) | (x′, y′) ∈ R′} – (f, g) : (f, g)∗R → R is opcartesian over (f, g)

  • U is (thus) a bifibration
  • Rel(X, Y ) is the fibre over (X, Y )
slide-22
SLIDE 22

Reynolds’ Semantics of Types, Fibrationally

  • Recall:

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!

slide-23
SLIDE 23

Reynolds’ Semantics of Types, Fibrationally

  • Recall:

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!

  • If each Ri : Rel(Xi, Yi), then [

[∆ ⊢ τ] ]rR : Rel([ [∆ ⊢ τ] ]oX, [ [∆ ⊢ τ] ]oY )

slide-24
SLIDE 24

Reynolds’ Semantics of Types, Fibrationally

  • Recall:

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!

  • If each Ri : Rel(Xi, Yi), then [

[∆ ⊢ τ] ]rR : Rel([ [∆ ⊢ τ] ]oX, [ [∆ ⊢ τ] ]oY )

  • Theorem (Reynolds’ Semantics of Types, Fibrationally) Let U be the

relations fibration on Set. Every judgement ∆ ⊢ τ induces a fibred functor [ [∆ ⊢ τ] ] : |U||∆| → U. |Rel||∆|

[ [∆⊢τ] ]r

  • |U||∆|
  • Rel

U

  • |Set||∆| × |Set||∆|

[ [∆⊢τ] ]o×[ [∆⊢τ] ]o

Set × Set

slide-25
SLIDE 25

Reynolds’ Semantics of Types, Fibrationally

  • Recall:

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!

  • If each Ri : Rel(Xi, Yi), then [

[∆ ⊢ τ] ]rR : Rel([ [∆ ⊢ τ] ]oX, [ [∆ ⊢ τ] ]oY )

  • Theorem (Reynolds’ Semantics of Types, Fibrationally) Let U be the

relations fibration on Set. Every judgement ∆ ⊢ τ induces a fibred functor [ [∆ ⊢ τ] ] : |U||∆| → U. |Rel||∆|

[ [∆⊢τ] ]r

  • |U||∆|
  • Rel

U

  • |Set||∆| × |Set||∆|

[ [∆⊢τ] ]o×[ [∆⊢τ] ]o

Set × Set

  • We use discrete categories in the domain of [

[∆ ⊢ τ] ] to reflect the fact that Reynolds did not give a functorial action of types on morphisms

slide-26
SLIDE 26

Identity Extension Lemma, Fibrationally

  • If ∆ ⊢ τ then

[ [∆ ⊢ τ] ]r (Eq X1, ..., Eq X|∆|) = Eq ([ [∆ ⊢ τ] ]o(X1, ..., X|∆|))

slide-27
SLIDE 27

Identity Extension Lemma, Fibrationally

  • If ∆ ⊢ τ then

[ [∆ ⊢ τ] ]r (Eq X1, ..., Eq X|∆|) = Eq ([ [∆ ⊢ τ] ]o(X1, ..., X|∆|))

  • Theorem (Identity Extension Lemma, Fibrationally) If ∆ ⊢ τ then

[ [∆ ⊢ τ] ]r ◦ |Eq||∆| = Eq ◦ [ [∆ ⊢ τ] ]o |Rel||∆|

[ [∆⊢τ] ]r

Rel

|Set||∆|

|Eq||∆|

  • [

[∆⊢τ] ]o

Set

Eq

slide-28
SLIDE 28

Abstraction Theorem, Fibrationally

  • Suppose Reynolds had given relational interpretations for terms such

that [ [∆; Γ ⊢ t : τ] ]rR is over [ [∆; Γ ⊢ t : τ] ]oX × [ [∆; Γ ⊢ t : τ] ]oY

slide-29
SLIDE 29

Abstraction Theorem, Fibrationally

  • Suppose Reynolds had given relational interpretations for terms such

that [ [∆; Γ ⊢ t : τ] ]rR is over [ [∆; Γ ⊢ t : τ] ]oX × [ [∆; Γ ⊢ t : τ] ]oY

  • Abstraction Theorem Let X, Y : Set|∆|, R : Rel|∆|(X, Y ), A ∈ [

[∆ ⊢ Γ] ]oX, and B ∈ [ [∆ ⊢ Γ] ]oY . For every ∆; Γ ⊢ t : τ, if (A, B) ∈ [ [∆ ⊢ Γ] ]rR, then ([ [∆; Γ ⊢ t : τ] ]o X A, [ [∆; Γ ⊢ t : τ] ]o Y B) ∈ [ [∆ ⊢ τ] ]rR.

slide-30
SLIDE 30

Abstraction Theorem, Fibrationally

  • Suppose Reynolds had given relational interpretations for terms such

that [ [∆; Γ ⊢ t : τ] ]rR is over [ [∆; Γ ⊢ t : τ] ]oX × [ [∆; Γ ⊢ t : τ] ]oY

  • Abstraction Theorem Let X, Y : Set|∆|, R : Rel|∆|(X, Y ), A ∈ [

[∆ ⊢ Γ] ]oX, and B ∈ [ [∆ ⊢ Γ] ]oY . For every ∆; Γ ⊢ t : τ, if (A, B) ∈ [ [∆ ⊢ Γ] ]rR, then ([ [∆; Γ ⊢ t : τ] ]o X A, [ [∆; Γ ⊢ t : τ] ]o Y B) ∈ [ [∆ ⊢ τ] ]rR.

  • Theorem (Abstraction Theorem, Fibrationally) Every term ∆; Γ ⊢ t :

τ is interpreted as a fibred natural transformation ([ [∆; Γ ⊢ t : τ] ]o × [ [∆; Γ ⊢ t : τ] ]o, [ [∆; Γ ⊢ t : τ] ]r) : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ] ] |Rel||∆|

[ [Γ] ]r

  • [

[τ] ]r

  • [

[t] ]r |U||∆|

  • Rel

U

  • |Set||∆| × |Set||∆|

[ [Γ] ]o×[ [Γ] ]o

  • [

[τ] ]o×[ [τ] ]o

  • [

[t] ]o×[ [t] ]o Set × Set

slide-31
SLIDE 31

Unpacking the Fibrational Abstraction Theorem

  • The domains of [

[∆ ⊢ Γ] ]o and [ [∆ ⊢ τ] ]o are discrete

slide-32
SLIDE 32

Unpacking the Fibrational Abstraction Theorem

  • The domains of [

[∆ ⊢ Γ] ]o and [ [∆ ⊢ τ] ]o are discrete

  • [

[∆; Γ ⊢ t : τ] ]o : [ [∆ ⊢ Γ] ]o → [ [∆ ⊢ τ] ]o is a (vacuously) natural transformation

slide-33
SLIDE 33

Unpacking the Fibrational Abstraction Theorem

  • The domains of [

[∆ ⊢ Γ] ]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

slide-34
SLIDE 34

Unpacking the Fibrational Abstraction Theorem

  • The domains of [

[∆ ⊢ Γ] ]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

slide-35
SLIDE 35

Unpacking the Fibrational Abstraction Theorem

  • The domains of [

[∆ ⊢ Γ] ]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

  • That is, [

[∆; Γ ⊢ 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

slide-36
SLIDE 36

Unpacking the Fibrational Abstraction Theorem

  • The domains of [

[∆ ⊢ Γ] ]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

  • That is, [

[∆; Γ ⊢ 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

  • This is the conclusion of Reynolds’ original statement of the theorem!!!
slide-37
SLIDE 37

The Take-Away

  • Reynolds’ original formulation of the Abstraction Theorem seems like

it asserts a property of [ [∆; Γ ⊢ t : τ] ]o

slide-38
SLIDE 38

The Take-Away

  • Reynolds’ original formulation of the Abstraction Theorem seems like

it asserts a property of [ [∆; Γ ⊢ t : τ] ]o

  • But it really states the existence of additional algebraic structure given

by the interpretations [ [∆; Γ ⊢ t : τ] ]r of terms as fibred natural trans- formations

slide-39
SLIDE 39

The Take-Away

  • Reynolds’ original formulation of the Abstraction Theorem seems like

it asserts a property of [ [∆; Γ ⊢ t : τ] ]o

  • But it really states the existence of additional algebraic structure given

by the interpretations [ [∆; Γ ⊢ t : τ] ]r of terms as fibred natural trans- formations

  • This point of view

– exposes this heretofore hidden structure

slide-40
SLIDE 40

The Take-Away

  • Reynolds’ original formulation of the Abstraction Theorem seems like

it asserts a property of [ [∆; Γ ⊢ t : τ] ]o

  • But it really states the existence of additional algebraic structure given

by the interpretations [ [∆; Γ ⊢ t : τ] ]r of terms as fibred natural trans- formations

  • This point of view

– exposes this heretofore hidden structure – opens the way to our generalization of Reynolds’ construction

slide-41
SLIDE 41

The Take-Away

  • Reynolds’ original formulation of the Abstraction Theorem seems like

it asserts a property of [ [∆; Γ ⊢ t : τ] ]o

  • But it really states the existence of additional algebraic structure given

by the interpretations [ [∆; Γ ⊢ t : τ] ]r of terms as fibred natural trans- formations

  • This point of view

– exposes this heretofore hidden structure – opens the way to our generalization of Reynolds’ construction

  • To generalize [

[−] ]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

slide-42
SLIDE 42

Relations Fibrations

  • Observe: The relations fibration on Set arises from the subobject fi-

bration over Set by pullback, or change of base

slide-43
SLIDE 43

Relations Fibrations

  • Observe: The relations fibration on Set arises from the subobject fi-

bration over Set by pullback, or change of base

  • If U : E → B is a fibration and B has products, then the fibration

Rel(U) : Rel(E) → B × B is defined by Rel(E)

q

  • Rel(U)
  • E

U

  • B × B ×

B

slide-44
SLIDE 44

Relations Fibrations

  • Observe: The relations fibration on Set arises from the subobject fi-

bration over Set by pullback, or change of base

  • If U : E → B is a fibration and B has products, then the fibration

Rel(U) : Rel(E) → B × B is defined by Rel(E)

q

  • Rel(U)
  • E

U

  • B × B ×

B

  • Rel(U) is the relations fibration for U
slide-45
SLIDE 45

Relations Fibrations

  • Observe: The relations fibration on Set arises from the subobject fi-

bration over Set by pullback, or change of base

  • If U : E → B is a fibration and B has products, then the fibration

Rel(U) : Rel(E) → B × B is defined by Rel(E)

q

  • Rel(U)
  • E

U

  • B × B ×

B

  • Rel(U) is the relations fibration for U
  • The objects of Rel(E) are called relations on B
slide-46
SLIDE 46

The Truth Functor

  • U : E → B has fibred terminal objects if

– each fibre EX of E has a terminal object KX

slide-47
SLIDE 47

The Truth Functor

  • U : E → B has fibred terminal objects if

– 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

slide-48
SLIDE 48

The Truth Functor

  • U : E → B has fibred terminal objects if

– 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

  • The map sending each object X of B to KX extends to a functor

K : B → E called the truth functor for U

slide-49
SLIDE 49

The Equality Functor

  • Let U : E → B be a bifibration with fibred terminal objects, suppose B

has products, and let δX be the diagonal morphism δX : X → X × X

slide-50
SLIDE 50

The Equality Functor

  • Let U : E → B be a bifibration with fibred terminal objects, suppose B

has products, and let δX be the diagonal morphism δX : X → X × X

  • The map sending each object X of B to ΣδXKX extends to a functor

Eq : B → Rel(E) called the equality functor for Rel(U) E

U

  • KX

(δX)§

ΣδX(KX)

B X

δX

X × X

slide-51
SLIDE 51

The Equality Functor

  • Let U : E → B be a bifibration with fibred terminal objects, suppose B

has products, and let δX be the diagonal morphism δX : X → X × X

  • The map sending each object X of B to ΣδXKX extends to a functor

Eq : B → Rel(E) called the equality functor for Rel(U) E

U

  • KX

(δX)§

ΣδX(KX)

B X

δX

X × X

  • Intuitively, KX acts like a characteristic function for X
slide-52
SLIDE 52

The Equality Functor

  • Let U : E → B be a bifibration with fibred terminal objects, suppose B

has products, and let δX be the diagonal morphism δX : X → X × X

  • The map sending each object X of B to ΣδXKX extends to a functor

Eq : B → Rel(E) called the equality functor for Rel(U) E

U

  • KX

(δX)§

ΣδX(KX)

B X

δX

X × X

  • Intuitively, KX acts like a characteristic function for X
  • So opreindexing KX along δ gives a “binary predicate” — i.e., a

relation — that acts like a characteristic function for the diagonal of X × X

slide-53
SLIDE 53

The Equality Functor

  • Let U : E → B be a bifibration with fibred terminal objects, suppose B

has products, and let δX be the diagonal morphism δX : X → X × X

  • The map sending each object X of B to ΣδXKX extends to a functor

Eq : B → Rel(E) called the equality functor for Rel(U) E

U

  • KX

(δX)§

ΣδX(KX)

B X

δX

X × X

  • Intuitively, KX acts like a characteristic function for X
  • So opreindexing KX along δ gives a “binary predicate” — i.e., a

relation — that acts like a characteristic function for the diagonal of X × X

  • That is, ΣδX(KX) acts like an equality relation on X
slide-54
SLIDE 54

Some Observations

  • This definition specializes to the function mapping each set X to

{(x, x) | x ∈ X} when instantiated to the relations fibration on Set

slide-55
SLIDE 55

Some Observations

  • This definition specializes to the function mapping each set X to

{(x, x) | x ∈ X} when instantiated to the relations fibration on Set

  • Eq is faithful
slide-56
SLIDE 56

Some Observations

  • This definition specializes to the function mapping each set X to

{(x, x) | x ∈ X} when instantiated to the relations fibration on Set

  • Eq is faithful
  • Eq is not always full

Counterexample: Eq for Id : Set → Set

slide-57
SLIDE 57

Some Observations

  • This definition specializes to the function mapping each set X to

{(x, x) | x ∈ X} when instantiated to the relations fibration on Set

  • Eq is faithful
  • Eq is not always full

Counterexample: Eq for Id : Set → Set

  • For the definition of Eq we only need opreindexing along diagonals δX
slide-58
SLIDE 58

Some Observations

  • This definition specializes to the function mapping each set X to

{(x, x) | x ∈ X} when instantiated to the relations fibration on Set

  • Eq is faithful
  • Eq is not always full

Counterexample: Eq for Id : Set → Set

  • For the definition of Eq we only need opreindexing along diagonals δX
  • But we actually want to have graph relations in our models, so we

need to be able to opreindex along arbitrary morphisms

slide-59
SLIDE 59

Some Observations

  • This definition specializes to the function mapping each set X to

{(x, x) | x ∈ X} when instantiated to the relations fibration on Set

  • Eq is faithful
  • Eq is not always full

Counterexample: Eq for Id : Set → Set

  • For the definition of Eq we only need opreindexing along diagonals δX
  • But we actually want to have graph relations in our models, so we

need to be able to opreindex along arbitrary morphisms

  • Also, to recover the standard results about graph relations and initial

algebras in parametric models, in the paper we need that Eq is full

slide-60
SLIDE 60

Some Observations

  • This definition specializes to the function mapping each set X to

{(x, x) | x ∈ X} when instantiated to the relations fibration on Set

  • Eq is faithful
  • Eq is not always full

Counterexample: Eq for Id : Set → Set

  • For the definition of Eq we only need opreindexing along diagonals δX
  • But we actually want to have graph relations in our models, so we

need to be able to opreindex along arbitrary morphisms

  • Also, to recover the standard results about graph relations and initial

algebras in parametric models, in the paper we need that Eq is full

  • But these issues will not arise in this course
slide-61
SLIDE 61

Generalizing Reynolds’ Construction

  • Interpret System F types as fibred functors with discrete domains
slide-62
SLIDE 62

Generalizing Reynolds’ Construction

  • Interpret System F types as fibred functors with discrete domains
  • Interpret System F terms as fibred natural transformations between

such fibred functors

slide-63
SLIDE 63

Generalizing Reynolds’ Construction

  • Interpret System F types as fibred functors with discrete domains
  • Interpret System F terms as fibred natural transformations between

such fibred functors

  • Produce a model of System F for which (fibrational versions of) the

IEL and the Abstraction Theorem hold

slide-64
SLIDE 64

Generalizing Reynolds’ Construction

  • Interpret System F types as fibred functors with discrete domains
  • Interpret System F terms as fibred natural transformations between

such fibred functors

  • Produce a model of System F for which (fibrational versions of) the

IEL and the Abstraction Theorem hold

  • This model is actually a λ2-fibration
slide-65
SLIDE 65

Generalizing Reynolds’ Construction

  • Interpret System F types as fibred functors with discrete domains
  • Interpret System F terms as fibred natural transformations between

such fibred functors

  • Produce a model of System F for which (fibrational versions of) the

IEL and the Abstraction Theorem hold

  • This model is actually a λ2-fibration
  • Seely showed that we can always interpret System F soundly in such

fibrations

slide-66
SLIDE 66

Structure for Interpreting Types - arrow types

  • Observe:

– Reynolds’ definitions of [ [∆ ⊢ τ1 → τ2] ]o and [ [∆ ⊢ τ1 → τ2] ]r are derived from the cartesian closed structure of Set and Rel

slide-67
SLIDE 67

Structure for Interpreting Types - arrow types

  • Observe:

– 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

slide-68
SLIDE 68

Structure for Interpreting Types - arrow types

  • Observe:

– 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

slide-69
SLIDE 69

Structure for Interpreting Types - arrow types

  • Observe:

– 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

  • Conclude: Arrow types can be modeled “parametrically” — i.e., so

that the Abstraction Theorem holds — by a fibration U : E → B if

slide-70
SLIDE 70

Structure for Interpreting Types - arrow types

  • Observe:

– 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

  • Conclude: Arrow types can be modeled “parametrically” — i.e., so

that the Abstraction Theorem holds — by a fibration U : E → B if – E and B are cartesian closed categories

slide-71
SLIDE 71

Structure for Interpreting Types - arrow types

  • Observe:

– 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

  • Conclude: Arrow types can be modeled “parametrically” — i.e., so

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

slide-72
SLIDE 72

Equality Preserving Arrow Fibrations

  • U : E → B is an arrow fibration if

– E and B are cartesian closed – U preserves the cartesian closed structure

slide-73
SLIDE 73

Equality Preserving Arrow Fibrations

  • U : E → B is an arrow fibration if

– E and B are cartesian closed – U preserves the cartesian closed structure

  • If U : E → B and B is a CCC, then Rel(U) is an equality preserving

arrow fibration if

slide-74
SLIDE 74

Equality Preserving Arrow Fibrations

  • U : E → B is an arrow fibration if

– E and B are cartesian closed – U preserves the cartesian closed structure

  • If U : E → B and B is a CCC, then Rel(U) is an equality preserving

arrow fibration if – Rel(U) is an arrow fibration

slide-75
SLIDE 75

Equality Preserving Arrow Fibrations

  • U : E → B is an arrow fibration if

– E and B are cartesian closed – U preserves the cartesian closed structure

  • If U : E → B and B is a CCC, then Rel(U) is an equality preserving

arrow fibration if – Rel(U) is an arrow fibration – for all X and Y in B Eq (X ⇒ Y ) ∼ = (Eq X ⇒ Eq Y )

slide-76
SLIDE 76

Equality Preserving Arrow Fibrations

  • U : E → B is an arrow fibration if

– E and B are cartesian closed – U preserves the cartesian closed structure

  • If U : E → B and B is a CCC, then Rel(U) is an equality preserving

arrow fibration if – Rel(U) is an arrow fibration – for all X and Y in B Eq (X ⇒ Y ) ∼ = (Eq X ⇒ Eq Y )

  • There are reasonable hypotheses on U making Rel(U) an equality pre-

serving arrow fibration (see MFPS’15 and FoSSaCS’16)

slide-77
SLIDE 77

Structure for Interpreting Types - forall types

  • The rules for type abstraction and type application suggest interpret-

ing ∀ as right adjoint to weakening by a type variable

slide-78
SLIDE 78

Structure for Interpreting Types - forall types

  • The rules for type abstraction and type application suggest interpret-

ing ∀ as right adjoint to weakening by a type variable

  • Naive Idea: Try to look for such an adjoint on the base category, then

another on the total category, and then try to link these adjoints

slide-79
SLIDE 79

Structure for Interpreting Types - forall types

  • The rules for type abstraction and type application suggest interpret-

ing ∀ as right adjoint to weakening by a type variable

  • Naive Idea: Try to look for such an adjoint on the base category, then

another on the total category, and then try to link these adjoints

  • This is wrong: For U : Rel → Set × Set this gives all polymorphic

functions, not just the parametrically polymorphic ones!

slide-80
SLIDE 80

Structure for Interpreting Types - forall types

  • The rules for type abstraction and type application suggest interpret-

ing ∀ as right adjoint to weakening by a type variable

  • Naive Idea: Try to look for such an adjoint on the base category, then

another on the total category, and then try to link these adjoints

  • This is wrong: For U : Rel → Set × Set this gives all polymorphic

functions, not just the parametrically polymorphic ones!

  • Instead: Require an adjoint for the combined fibred semantics
slide-81
SLIDE 81

Structure for Interpreting Types - forall types

  • The rules for type abstraction and type application suggest interpret-

ing ∀ as right adjoint to weakening by a type variable

  • Naive Idea: Try to look for such an adjoint on the base category, then

another on the total category, and then try to link these adjoints

  • This is wrong: For U : Rel → Set × Set this gives all polymorphic

functions, not just the parametrically polymorphic ones!

  • Instead: Require an adjoint for the combined fibred semantics
  • |Rel(U)|n →Eq Rel(U) has
slide-82
SLIDE 82

Structure for Interpreting Types - forall types

  • The rules for type abstraction and type application suggest interpret-

ing ∀ as right adjoint to weakening by a type variable

  • Naive Idea: Try to look for such an adjoint on the base category, then

another on the total category, and then try to link these adjoints

  • This is wrong: For U : Rel → Set × Set this gives all polymorphic

functions, not just the parametrically polymorphic ones!

  • Instead: Require an adjoint for the combined fibred semantics
  • |Rel(U)|n →Eq Rel(U) has

– Objects: equality preserving fibred functors from |Rel(U)|n to Rel(U)

slide-83
SLIDE 83

Structure for Interpreting Types - forall types

  • The rules for type abstraction and type application suggest interpret-

ing ∀ as right adjoint to weakening by a type variable

  • Naive Idea: Try to look for such an adjoint on the base category, then

another on the total category, and then try to link these adjoints

  • This is wrong: For U : Rel → Set × Set this gives all polymorphic

functions, not just the parametrically polymorphic ones!

  • Instead: Require an adjoint for the combined fibred semantics
  • |Rel(U)|n →Eq Rel(U) has

– Objects: equality preserving fibred functors from |Rel(U)|n to Rel(U) – Morphisms: fibred natural transformations between them

slide-84
SLIDE 84

Structure for Interpreting Types - forall types

  • The rules for type abstraction and type application suggest interpret-

ing ∀ as right adjoint to weakening by a type variable

  • Naive Idea: Try to look for such an adjoint on the base category, then

another on the total category, and then try to link these adjoints

  • This is wrong: For U : Rel → Set × Set this gives all polymorphic

functions, not just the parametrically polymorphic ones!

  • Instead: Require an adjoint for the combined fibred semantics
  • |Rel(U)|n →Eq Rel(U) has

– Objects: equality preserving fibred functors from |Rel(U)|n to Rel(U) – Morphisms: fibred natural transformations between them

  • Note the use of discrete categories
slide-85
SLIDE 85

∀-Fibrations

  • Rel(U) is a ∀-fibration if

– for every projection πn : |Rel(U)|n+1 → |Rel(U)|n, the functor

  • πn : (|Rel(U)|n →Eq Rel(U)) → (|Rel(U)|n+1 →Eq Rel(U))

has a right adjoint ∀n

slide-86
SLIDE 86

∀-Fibrations

  • Rel(U) is a ∀-fibration if

– for every projection πn : |Rel(U)|n+1 → |Rel(U)|n, the functor

  • πn : (|Rel(U)|n →Eq Rel(U)) → (|Rel(U)|n+1 →Eq Rel(U))

has a right adjoint ∀n – this family of adjunctions is natural in n

slide-87
SLIDE 87

∀-Fibrations

  • Rel(U) is a ∀-fibration if

– for every projection πn : |Rel(U)|n+1 → |Rel(U)|n, the functor

  • πn : (|Rel(U)|n →Eq Rel(U)) → (|Rel(U)|n+1 →Eq Rel(U))

has a right adjoint ∀n – this family of adjunctions is natural in n

  • Then for all F : |Rel(U)|n →Eq Rel(U) and G : |Rel(U)|n+1 →Eq Rel(U)

there is an isomorphism ϕn : Hom(F ◦ πn, G) ∼ = Hom(F, ∀G) that is natural in n

slide-88
SLIDE 88

Coming Up

  • Use relations fibrations that are equality preserving arrow fibrations

and ∀-fibrations to interpret System F types as fibred functors and System F terms as fibred natural transformations

slide-89
SLIDE 89

References

  • Parametric polymorphism — universally. N. Ghani, F. Nordvall Fors-

berg, and F. Orsanigo. WadlerFest’16.

  • Comprehensive parametric polymorphism: categorical models and type
  • theory. N. Ghani, F. Nordvall Forsberg, and A. Simpson. FoSSaCS’16.
  • Categorical semantics for higher-order polymorphic lambda calculus.
  • R. A. Seely. Journal of Symbolic Computation, 1987.