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?

  • Last time we set up all the infrastructure we need to give our bifibra-

tional parametric model of System F

slide-5
SLIDE 5

Where Were We?

  • Last time we set up all the infrastructure we need to give our bifibra-

tional parametric model of System F

  • Today we will use relations fibrations on categories other than Set

that are both equality preserving arrow fibrations and ∀-fibrations to interpret System F

slide-6
SLIDE 6

Where Were We?

  • Last time we set up all the infrastructure we need to give our bifibra-

tional parametric model of System F

  • Today we will use relations fibrations on categories other than Set

that are both equality preserving arrow fibrations and ∀-fibrations to interpret System F – types as fibred functors

slide-7
SLIDE 7

Where Were We?

  • Last time we set up all the infrastructure we need to give our bifibra-

tional parametric model of System F

  • Today we will use relations fibrations on categories other than Set

that are both equality preserving arrow fibrations and ∀-fibrations to interpret System F – types as fibred functors – terms as fibred natural transformations

slide-8
SLIDE 8

Where Were We?

  • Last time we set up all the infrastructure we need to give our bifibra-

tional parametric model of System F

  • Today we will use relations fibrations on categories other than Set

that are both equality preserving arrow fibrations and ∀-fibrations to interpret System F – types as fibred functors – terms as fibred natural transformations

  • This gives very general parametric models for System F
slide-9
SLIDE 9

Where Were We?

  • Last time we set up all the infrastructure we need to give our bifibra-

tional parametric model of System F

  • Today we will use relations fibrations on categories other than Set

that are both equality preserving arrow fibrations and ∀-fibrations to interpret System F – types as fibred functors – terms as fibred natural transformations

  • This gives very general parametric models for System F
  • Throughout, let Rel(U) be an equality preserving arrow fibration and

∀-fibration

slide-10
SLIDE 10

Fibrational Semantics of Types

  • Define fibred functors

[ [∆ ⊢ τ] ] : |Rel(U)||∆| → Rel(U) by

slide-11
SLIDE 11

Fibrational Semantics of Types

  • Define fibred functors

[ [∆ ⊢ τ] ] : |Rel(U)||∆| → Rel(U) by – Type variables: [ [∆ ⊢ αi] ]oX = Xi and [ [∆ ⊢ αi] ]rR = Ri

slide-12
SLIDE 12

Fibrational Semantics of Types

  • Define fibred functors

[ [∆ ⊢ τ] ] : |Rel(U)||∆| → Rel(U) by – Type variables: [ [∆ ⊢ αi] ]oX = Xi and [ [∆ ⊢ αi] ]rR = Ri – Arrow types: [ [∆ ⊢ τ1 → τ2] ] = [ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ]

slide-13
SLIDE 13

Fibrational Semantics of Types

  • Define fibred functors

[ [∆ ⊢ τ] ] : |Rel(U)||∆| → Rel(U) by – Type variables: [ [∆ ⊢ αi] ]oX = Xi and [ [∆ ⊢ αi] ]rR = Ri – Arrow types: [ [∆ ⊢ τ1 → τ2] ] = [ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ] – Forall types: [ [∆ ⊢ ∀α.τ] ] = ∀[ [∆, α ⊢ τ] ]

slide-14
SLIDE 14

Fibrational Semantics of Types

  • Define fibred functors

[ [∆ ⊢ τ] ] : |Rel(U)||∆| → Rel(U) by – Type variables: [ [∆ ⊢ αi] ]oX = Xi and [ [∆ ⊢ αi] ]rR = Ri – Arrow types: [ [∆ ⊢ τ1 → τ2] ] = [ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ] – Forall types: [ [∆ ⊢ ∀α.τ] ] = ∀[ [∆, α ⊢ τ] ]

  • No definition for [

[∆ ⊢ τ] ] on morphisms is needed because the domain

  • f [

[∆ ⊢ τ] ] is discrete

slide-15
SLIDE 15

Type Interpretations are Equality Preserving

  • Proposition The interpretation of every System F type is an equality

preserving fibred functor

slide-16
SLIDE 16

Type Interpretations are Equality Preserving

  • Proposition The interpretation of every System F type is an equality

preserving fibred functor

  • Proof: By induction on the structure of τ
slide-17
SLIDE 17

Type Interpretations are Equality Preserving

  • Proposition The interpretation of every System F type is an equality

preserving fibred functor

  • Proof: By induction on the structure of τ
  • If τ = ∀α.τ ′, then [

[∆ ⊢ τ] ] = ∀[ [∆, α ⊢ τ ′] ] 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))

slide-18
SLIDE 18

Type Interpretations are Equality Preserving

  • Proposition The interpretation of every System F type is an equality

preserving fibred functor

  • Proof: By induction on the structure of τ
  • If τ = ∀α.τ ′, then [

[∆ ⊢ τ] ] = ∀[ [∆, α ⊢ τ ′] ] 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))

  • Indeed, the very existence of ∀ in a ∀-fibration requires that if F is

equality preserving then so is ∀F

slide-19
SLIDE 19

Type Interpretations are Equality Preserving

  • Proposition The interpretation of every System F type is an equality

preserving fibred functor

  • Proof: By induction on the structure of τ
  • If τ = ∀α.τ ′, then [

[∆ ⊢ τ] ] = ∀[ [∆, α ⊢ τ ′] ] 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))

  • Indeed, the very existence of ∀ in a ∀-fibration requires that if F is

equality preserving then so is ∀F

  • In our model, the Identity Extension Lemma is “baked into” the inter-

pretation of types, rather than something to be proved post facto

slide-20
SLIDE 20

Type Interpretations are Equality Preserving

  • Proposition The interpretation of every System F type is an equality

preserving fibred functor

  • Proof: By induction on the structure of τ.
  • If τ = ∀α.τ ′, then [

[∆ ⊢ τ] ] = ∀[ [∆, α ⊢ τ ′] ] 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))

  • Indeed, the very existence of ∀ in a ∀-fibration requires that if F is

equality preserving then so is ∀F

  • In our model, the Identity Extension Lemma is “baked into” the inter-

pretation of types, rather than something to be proved post facto

  • If U is faithful, then the ∀-fibration requirement can be reformulated

in terms of more basic concepts using opfibrational structure of U

slide-21
SLIDE 21

Fibrational Semantics of Terms - The Set Up

  • In a CCC, for all X and Y , there is an object X ⇒ Y and a isomor-

phism λ : Hom(W × X, Y ) ∼ = Hom(W, X ⇒ Y ) that is natural in W

slide-22
SLIDE 22

Fibrational Semantics of Terms - The Set Up

  • In a CCC, for all X and Y , there is an object X ⇒ Y and a isomor-

phism λ : Hom(W × X, Y ) ∼ = Hom(W, X ⇒ Y ) that is natural in W

  • The unit of this adjunction is the evaluation map

evX,Y = λ−1(id X⇒Y ) : (X ⇒ Y ) × X → Y

slide-23
SLIDE 23

Fibrational Semantics of Terms - The Set Up

  • In a CCC, for all X and Y , there is an object X ⇒ Y and a isomor-

phism λ : Hom(W × X, Y ) ∼ = Hom(W, X ⇒ Y ) that is natural in W

  • The unit of this adjunction is the evaluation map

evX,Y = λ−1(id X⇒Y ) : (X ⇒ Y ) × X → Y

  • In a ∀-fibration, for every F and G, there is are isomorphisms

ϕn : Hom(F ◦ πn, G) ∼ = Hom(F, ∀nG) that are natural in n

slide-24
SLIDE 24

Fibrational Semantics of Terms - term variables

Define fibred natural transformations [ [∆; Γ ⊢ t : τ] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ] ] by

slide-25
SLIDE 25

Fibrational Semantics of Terms - term variables

Define fibred natural transformations [ [∆; Γ ⊢ t : τ] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ] ] by

  • If

∆ ⊢ τi xi : τi ∈ Γ ∆; Γ ⊢ xi : τi then [ [∆; Γ ⊢ xi : τi] ] = πi

slide-26
SLIDE 26

Fibrational Semantics of Terms - term variables

Define fibred natural transformations [ [∆; Γ ⊢ t : τ] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ] ] by

  • If

∆ ⊢ τi xi : τi ∈ Γ ∆; Γ ⊢ xi : τi then [ [∆; Γ ⊢ xi : τi] ] = πi

  • πi is the ith projection on both B and E
slide-27
SLIDE 27

Fibrational Semantics of Terms - term variables

Define fibred natural transformations [ [∆; Γ ⊢ t : τ] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ] ] by

  • If

∆ ⊢ τi xi : τi ∈ Γ ∆; Γ ⊢ xi : τi then [ [∆; Γ ⊢ xi : τi] ] = πi

  • πi is the ith projection on both B and E
  • This specializes to our Set interpretation of variables
slide-28
SLIDE 28

Fibrational Semantics of Terms - term abstractions

  • If

∆; Γ, x : τ1 ⊢ t : τ2 ∆; Γ ⊢ λx.t : τ1 → τ2 then [ [∆; Γ ⊢ λx.t : τ1 → τ2] ] : [ [∆ ⊢ Γ] ] → ([ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ]) [ [∆; Γ ⊢ λx.t : τ1 → τ2] ] = λ[ [∆; Γ, x : τ1 ⊢ t : τ2] ]

slide-29
SLIDE 29

Fibrational Semantics of Terms - term abstractions

  • If

∆; Γ, x : τ1 ⊢ t : τ2 ∆; Γ ⊢ λx.t : τ1 → τ2 then [ [∆; Γ ⊢ λx.t : τ1 → τ2] ] : [ [∆ ⊢ Γ] ] → ([ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ]) [ [∆; Γ ⊢ λx.t : τ1 → τ2] ] = λ[ [∆; Γ, x : τ1 ⊢ t : τ2] ]

  • This is sensible because

[ [∆; Γ, x : τ1 ⊢ t : τ2] ] : [ [∆ ⊢ Γ] ] × [ [∆ ⊢ τ1] ] → [ [∆ ⊢ τ2] ]

slide-30
SLIDE 30

Fibrational Semantics of Terms - term abstractions

  • If

∆; Γ, x : τ1 ⊢ t : τ2 ∆; Γ ⊢ λx.t : τ1 → τ2 then [ [∆; Γ ⊢ λx.t : τ1 → τ2] ] : [ [∆ ⊢ Γ] ] → ([ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ]) [ [∆; Γ ⊢ λx.t : τ1 → τ2] ] = λ[ [∆; Γ, x : τ1 ⊢ t : τ2] ]

  • This is sensible because

[ [∆; Γ, x : τ1 ⊢ t : τ2] ] : [ [∆ ⊢ Γ] ] × [ [∆ ⊢ τ1] ] → [ [∆ ⊢ τ2] ]

  • λ is the right adjoint to × in both B and E
slide-31
SLIDE 31

Fibrational Semantics of Terms - term abstractions

  • If

∆; Γ, x : τ1 ⊢ t : τ2 ∆; Γ ⊢ λx.t : τ1 → τ2 then [ [∆; Γ ⊢ λx.t : τ1 → τ2] ] : [ [∆ ⊢ Γ] ] → ([ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ]) [ [∆; Γ ⊢ λx.t : τ1 → τ2] ] = λ[ [∆; Γ, x : τ1 ⊢ t : τ2] ]

  • This is sensible because

[ [∆; Γ, x : τ1 ⊢ t : τ2] ] : [ [∆ ⊢ Γ] ] × [ [∆ ⊢ τ1] ] → [ [∆ ⊢ τ2] ]

  • λ is the right adjoint to × in both B and E
  • This specializes to our Set interpretation of term abstractions
slide-32
SLIDE 32

Fibrational Semantics of Terms - term applications

  • If

∆; Γ ⊢ t1 : τ1 ∆; Γ ⊢ t2 : τ1 → τ2 ∆; Γ ⊢ t2t1 : τ2 then [ [∆; Γ ⊢ t2t1 : τ2] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ2] ] [ [∆; Γ ⊢ t2t1 : τ2] ] = evτ1,τ2 ◦ [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ]

slide-33
SLIDE 33

Fibrational Semantics of Terms - term applications

  • If

∆; Γ ⊢ t1 : τ1 ∆; Γ ⊢ t2 : τ1 → τ2 ∆; Γ ⊢ t2t1 : τ2 then [ [∆; Γ ⊢ t2t1 : τ2] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ2] ] [ [∆; Γ ⊢ t2t1 : τ2] ] = evτ1,τ2 ◦ [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ]

  • This is sensible because

[ [∆; Γ ⊢ t1 : τ1] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ1] ]

slide-34
SLIDE 34

Fibrational Semantics of Terms - term applications

  • If

∆; Γ ⊢ t1 : τ1 ∆; Γ ⊢ t2 : τ1 → τ2 ∆; Γ ⊢ t2t1 : τ2 then [ [∆; Γ ⊢ t2t1 : τ2] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ2] ] [ [∆; Γ ⊢ t2t1 : τ2] ] = evτ1,τ2 ◦ [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ]

  • This is sensible because

[ [∆; Γ ⊢ t1 : τ1] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ1] ] [ [∆; Γ ⊢ t2 : τ1 → τ2] ] : [ [∆ ⊢ Γ] ] → ([ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ])

slide-35
SLIDE 35

Fibrational Semantics of Terms - term applications

  • If

∆; Γ ⊢ t1 : τ1 ∆; Γ ⊢ t2 : τ1 → τ2 ∆; Γ ⊢ t2t1 : τ2 then [ [∆; Γ ⊢ t2t1 : τ2] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ2] ] [ [∆; Γ ⊢ t2t1 : τ2] ] = evτ1,τ2 ◦ [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ]

  • This is sensible because

[ [∆; Γ ⊢ t1 : τ1] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ1] ] [ [∆; Γ ⊢ t2 : τ1 → τ2] ] : [ [∆ ⊢ Γ] ] → ([ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ]) [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ] : [ [Γ] ] → ([ [τ1] ] ⇒ [ [τ2] ]) × [ [τ1] ]

slide-36
SLIDE 36

Fibrational Semantics of Terms - term applications

  • If

∆; Γ ⊢ t1 : τ1 ∆; Γ ⊢ t2 : τ1 → τ2 ∆; Γ ⊢ t2t1 : τ2 then [ [∆; Γ ⊢ t2t1 : τ2] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ2] ] [ [∆; Γ ⊢ t2t1 : τ2] ] = evτ1,τ2 ◦ [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ]

  • This is sensible because

[ [∆; Γ ⊢ t1 : τ1] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ1] ] [ [∆; Γ ⊢ t2 : τ1 → τ2] ] : [ [∆ ⊢ Γ] ] → ([ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ]) [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ] : [ [Γ] ] → ([ [τ1] ] ⇒ [ [τ2] ]) × [ [τ1] ]

  • −, − : (X → Y )×(X → W ) → X → (Y ×W ) is f, gX = fX ×gX
slide-37
SLIDE 37

Fibrational Semantics of Terms - term applications

  • If

∆; Γ ⊢ t1 : τ1 ∆; Γ ⊢ t2 : τ1 → τ2 ∆; Γ ⊢ t2t1 : τ2 then [ [∆; Γ ⊢ t2t1 : τ2] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ2] ] [ [∆; Γ ⊢ t2t1 : τ2] ] = evτ1,τ2 ◦ [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ]

  • This is sensible because

[ [∆; Γ ⊢ t1 : τ1] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ1] ] [ [∆; Γ ⊢ t2 : τ1 → τ2] ] : [ [∆ ⊢ Γ] ] → ([ [∆ ⊢ τ1] ] ⇒ [ [∆ ⊢ τ2] ]) [ [∆; Γ ⊢ t2 : τ1 → τ2] ], [ [∆; Γ ⊢ t1 : τ1] ] : [ [Γ] ] → ([ [τ1] ] ⇒ [ [τ2] ]) × [ [τ1] ]

  • −, − : (X → Y )×(X → W ) → X → (Y ×W ) is f, gX = fX ×gX
  • This specializes to our Set interpretation of term applications
slide-38
SLIDE 38

Fibrational Semantics of Terms - type abstractions

  • If

∆, α; Γ ⊢ t : τ ∆; Γ ⊢ Λα.t : ∀α.τ then [ [∆; Γ ⊢ Λα.t : ∀α.τ] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ ∀α.τ] ] = [ [∆ ⊢ Γ] ] → ∀[ [∆, α ⊢ τ] ] [ [∆; Γ ⊢ Λα.t : ∀α.τ] ] = ϕ|∆|[ [∆, α; Γ ⊢ t : τ] ]

  • This is sensible because α is not free in Γ, so

[ [∆, α; Γ ⊢ t : τ] ] : [ [∆, α ⊢ Γ] ] → [ [∆, α ⊢ τ] ] = [ [∆ ⊢ Γ] ] ◦ π|∆| → [ [∆, α ⊢ τ] ]

slide-39
SLIDE 39

Fibrational Semantics of Terms - type applications

  • If

∆; Γ ⊢ t : ∀α.τ2 ∆ ⊢ τ1 ∆; Γ ⊢ t τ1 : τ2[α → τ1] then [ [∆; Γ ⊢ t τ1 : τ2[α → τ1]] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ2[α → τ1]] ] [ [∆; Γ ⊢ t τ1 : τ2[α → τ1]] ] = ϕ−1

|∆|[

[∆; Γ ⊢ t : ∀α.τ2] ] ◦ id |∆|, [ [∆ ⊢ τ1] ]

  • This is sensible because

[ [∆; Γ ⊢ t : ∀α.τ2] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ ∀α.τ2] ] = [ [∆ ⊢ Γ] ] → ∀[ [∆, α ⊢ τ2] ]

slide-40
SLIDE 40

Validating β- and η-Rules

  • Our model is sensible by construction
slide-41
SLIDE 41

Validating β- and η-Rules

  • Our model is sensible by construction
  • Reynolds’ model is an instance of ours, assuming a constructive metathe-
  • ry — e.g., the Calculus of Constructions with impredicative Set
slide-42
SLIDE 42

Validating β- and η-Rules

  • Our model is sensible by construction
  • Reynolds’ model is an instance of ours, assuming a constructive metathe-
  • ry — e.g., the Calculus of Constructions with impredicative Set
  • Proposition If ∆ ⊢ τ1 and ∆, α; Γ ⊢ t : τ2
  • 1. [

[∆; Γ ⊢ (Λα.t)τ1 : τ2[α → τ1]] ] = [ [∆; Γ ⊢ t[α → τ1] : τ2[α → τ1]] ]

  • 2. [

[∆; Γ ⊢ t : ∀β.τ] ] = [ [∆; Γ ⊢ Λα.t α : ∀β.τ] ]

slide-43
SLIDE 43

Validating β- and η-Rules

  • Our model is sensible by construction
  • Reynolds’ model is an instance of ours, assuming a constructive metathe-
  • ry — e.g., the Calculus of Constructions with impredicative Set
  • Proposition If ∆ ⊢ τ1 and ∆, α; Γ ⊢ t : τ2
  • 1. [

[∆; Γ ⊢ (Λα.t)τ1 : τ2[α → τ1]] ] = [ [∆; Γ ⊢ t[α → τ1] : τ2[α → τ1]] ]

  • 2. [

[∆; Γ ⊢ t : ∀β.τ] ] = [ [∆; Γ ⊢ Λα.t α : ∀β.τ] ]

  • Proposition If ∆; Γ ⊢ t1 : τ1 and ∆; Γ, x : τ1 ⊢ t2 : τ2
  • 1. [

[∆; Γ ⊢ (λx.t2)t1 : τ2] ] = [ [∆; Γ ⊢ t2[x → t1] : τ2] ]

  • 2. [

[∆; Γ ⊢ t : τ1 → τ2] ] = [ [∆; Γ ⊢ λx.tx : τ1 → τ2] ]

slide-44
SLIDE 44

Reynolds’ Abstraction Theorem, Generalized

  • Our model actually gives rise to a λ2-fibration
slide-45
SLIDE 45

Reynolds’ Abstraction Theorem, Generalized

  • Our model actually gives rise to a λ2-fibration
  • Seely showed that λ2-fibrations always soundly interpret System F
slide-46
SLIDE 46

Reynolds’ Abstraction Theorem, Generalized

  • Our model actually gives rise to a λ2-fibration
  • Seely showed that λ2-fibrations always soundly interpret System F
  • Theorem If Rel(U) is an equality preserving arrow fibration and a

∀-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 : τ] ] : [ [∆ ⊢ Γ] ] → [ [∆ ⊢ τ] ]

slide-47
SLIDE 47

Reynolds’ Abstraction Theorem, Generalized

  • Our model actually gives rise to a λ2-fibration
  • Seely showed that λ2-fibrations always soundly interpret System F
  • Theorem If Rel(U) is an equality preserving arrow fibration and a

∀-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)||∆|

  • Rel(E)

U

  • |B||∆| × |B||∆|

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

  • [

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

  • [

[t] ]o×[ [t] ]o B × B

slide-48
SLIDE 48

Unwinding the Theorem

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:

slide-49
SLIDE 49

Unwinding the Theorem

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:

  • 1. An object interpretation of ∆ ⊢ τ as a functor [

[∆ ⊢ τ] ]o : |B||∆| → B

slide-50
SLIDE 50

Unwinding the Theorem

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:

  • 1. An object interpretation of ∆ ⊢ τ as a functor [

[∆ ⊢ τ] ]o : |B||∆| → B

  • 2. A relational interpretation of ∆ ⊢ τ as a functor [

[∆ ⊢ τ] ]r : |Rel(E)||∆| → Rel(E)

slide-51
SLIDE 51

Unwinding the Theorem

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:

  • 1. An object interpretation of ∆ ⊢ τ as a functor [

[∆ ⊢ τ] ]o : |B||∆| → B

  • 2. A relational interpretation of ∆ ⊢ τ as a functor [

[∆ ⊢ τ] ]r : |Rel(E)||∆| → Rel(E)

  • 3. A proof of the Identity Extension Lemma as in the previous lecture,

i.e., a proof that [ [∆ ⊢ τ] ] is equality preserving

slide-52
SLIDE 52

Unwinding the Theorem

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:

  • 1. An object interpretation of ∆ ⊢ τ as a functor [

[∆ ⊢ τ] ]o : |B||∆| → B

  • 2. A relational interpretation of ∆ ⊢ τ as a functor [

[∆ ⊢ τ] ]r : |Rel(E)||∆| → Rel(E)

  • 3. A proof of the Identity Extension Lemma as in the previous lecture,

i.e., a proof that [ [∆ ⊢ τ] ] is equality preserving

  • 4. An object interpretation of ∆; Γ ⊢ t : τ as a natural transformation

[ [∆; Γ ⊢ t : τ] ]o : [ [∆ ⊢ Γ] ]o → [ [∆ ⊢ τ] ]o

slide-53
SLIDE 53

Unwinding the Theorem

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:

  • 1. An object interpretation of ∆ ⊢ τ as a functor [

[∆ ⊢ τ] ]o : |B||∆| → B

  • 2. A relational interpretation of ∆ ⊢ τ as a functor [

[∆ ⊢ τ] ]r : |Rel(E)||∆| → Rel(E)

  • 3. A proof of the Identity Extension Lemma as in the previous lecture,

i.e., a proof that [ [∆ ⊢ τ] ] is equality preserving

  • 4. An object interpretation of ∆; Γ ⊢ t : τ as a natural transformation

[ [∆; Γ ⊢ t : τ] ]o : [ [∆ ⊢ Γ] ]o → [ [∆ ⊢ τ] ]o

  • 5. A proof of the Abstraction Theorem as in the previous lecture, i.e.,

a proof that ∆; Γ ⊢ t : τ has a relational interpretation as a natural transformation [ [∆; Γ ⊢ t : τ] ]r : [ [∆ ⊢ Γ] ]r → [ [∆ ⊢ τ] ]r over [ [∆; Γ ⊢ t : τ] ]o × [ [∆; Γ ⊢ t : τ] ]o.

slide-54
SLIDE 54

Additional Observations

  • Since we’ve actually constructed a λ2-fibration, we have a powerful

internal language for our model

slide-55
SLIDE 55

Additional Observations

  • Since we’ve actually constructed a λ2-fibration, we have a powerful

internal language for our model

  • We can use this language to reason about our model using System F
slide-56
SLIDE 56

Additional Observations

  • Since we’ve actually constructed a λ2-fibration, we have a powerful

internal language for our model

  • We can use this language to reason about our model using System F
  • This allows us to prove
slide-57
SLIDE 57

Additional Observations

  • Since we’ve actually constructed a λ2-fibration, we have a powerful

internal language for our model

  • We can use this language to reason about our model using System F
  • This allows us to prove

– our model has initial algebras for strong functors

slide-58
SLIDE 58

Additional Observations

  • Since we’ve actually constructed a λ2-fibration, we have a powerful

internal language for our model

  • We can use this language to reason about our model using System F
  • This allows us to prove

– our model has initial algebras for strong functors – our model has final coalgebras for strong functors

slide-59
SLIDE 59

Additional Observations

  • Since we’ve actually constructed a λ2-fibration, we have a powerful

internal language for our model

  • We can use this language to reason about our model using System F
  • This allows us to prove

– our model has initial algebras for strong functors – our model has final coalgebras for strong functors – parametricity implies dinaturality

slide-60
SLIDE 60

Additional Observations

  • Since we’ve actually constructed a λ2-fibration, we have a powerful

internal language for our model

  • We can use this language to reason about our model using System F
  • This allows us to prove

– our model has initial algebras for strong functors – our model has final coalgebras for strong functors – parametricity implies dinaturality

  • These are litmus tests verifying that a model is “good”
slide-61
SLIDE 61

Summing Up

  • Parametricity entails replacing usual categorical semantics involving

categories, functors, and natural transformations

slide-62
SLIDE 62

Summing Up

  • Parametricity entails replacing usual categorical semantics involving

categories, functors, and natural transformations with a semantics based on fibrations, fibred functors, and fibred natural transformations

slide-63
SLIDE 63

Summing Up

  • Parametricity entails replacing usual categorical semantics involving

categories, functors, and natural transformations with a semantics based on fibrations, fibred functors, and fibred natural transformations

  • This hits the sweet spot between the simplicity and “light structure”
  • f functorial models and the ability to prove expected key results
slide-64
SLIDE 64

Examples

  • The construction of examples of our framework is delicate
slide-65
SLIDE 65

Examples

  • The construction of examples of our framework is delicate
  • But several well-known models are instances of our framework
slide-66
SLIDE 66

Examples

  • The construction of examples of our framework is delicate
  • But several well-known models are instances of our framework
  • Some must be regarded as being internal to the Calculus of Construc-

tions with impredicative Set

slide-67
SLIDE 67

Examples

  • The construction of examples of our framework is delicate
  • But several well-known models are instances of our framework
  • Some must be regarded as being internal to the Calculus of Construc-

tions with impredicative Set

  • At least one must be be regarded as internal to the category of ω-sets
slide-68
SLIDE 68

Examples

  • The construction of examples of our framework is delicate
  • But several well-known models are instances of our framework
  • Some must be regarded as being internal to the Calculus of Construc-

tions with impredicative Set

  • At least one must be be regarded as internal to the category of ω-sets
  • They are discussed in the MFPS paper (and in the exercises!)
slide-69
SLIDE 69

Examples

  • The construction of examples of our framework is delicate
  • But several well-known models are instances of our framework
  • Some must be regarded as being internal to the Calculus of Construc-

tions with impredicative Set

  • At least one must be be regarded as internal to the category of ω-sets
  • They are discussed in the MFPS paper (and in the exercises!)
  • I ask you to show that the identity fibration Id : Set → Set is an

instance of our framework that models ad hoc polymorphism...

slide-70
SLIDE 70

Examples

  • The construction of examples of our framework is delicate
  • But several well-known models are instances of our framework
  • Some must be regarded as being internal to the Calculus of Construc-

tions with impredicative Set

  • At least one must be be regarded as internal to the category of ω-sets
  • They are discussed in the MFPS paper (and in the exercises!)
  • I ask you to show that the identity fibration Id : Set → Set is an

instance of our framework that models ad hoc polymorphism...

  • ...and to show that, ignoring size issues, Reynolds’ construction gives

an instance of our framework via the relations fibration on Set

slide-71
SLIDE 71

Examples

  • The construction of examples of our framework is delicate
  • But several well-known models are instances of our framework
  • Some must be regarded as being internal to the Calculus of Construc-

tions with impredicative Set

  • At least one must be be regarded as internal to the category of ω-sets
  • They are discussed in the MFPS paper (and in the exercises!)
  • I ask you to show that the identity fibration Id : Set → Set is an

instance of our framework that models ad hoc polymorphism...

  • ...and to show that, ignoring size issues, Reynolds’ construction gives

an instance of our framework via the relations fibration on Set

  • The PER model of Bainbridge et al. is also an instance (if bifibrations

are understood as internal to the category of ω-sets)

slide-72
SLIDE 72

A Prescriptive General Framework

  • Our framework is very general
slide-73
SLIDE 73

A Prescriptive General Framework

  • Our framework is very general
  • It is thus prescriptive, as well as descriptive
slide-74
SLIDE 74

A Prescriptive General Framework

  • Our framework is very general
  • It is thus prescriptive, as well as descriptive
  • Different fibrations give rise to parametric models with very different

flavors – changing the base category of the fibration changes the object model used to interpret types and terms

slide-75
SLIDE 75

A Prescriptive General Framework

  • Our framework is very general
  • It is thus prescriptive, as well as descriptive
  • Different fibrations give rise to parametric models with very different

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

slide-76
SLIDE 76

A Prescriptive General Framework

  • Our framework is very general
  • It is thus prescriptive, as well as descriptive
  • Different fibrations give rise to parametric models with very different

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

  • Ex: Using non-standard relations, we can construct a model of “multi-

valued parametricity” over a constructively completely distributive complete non-trivial lattice of truth values

slide-77
SLIDE 77

Extensions

  • At WoLLIC’15, Neil Ghani, Fredrik Nordvall Forsberg, and Federico

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

slide-78
SLIDE 78

Extensions

  • At WoLLIC’15, Neil Ghani, Fredrik Nordvall Forsberg, and Federico

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

  • At FoSSaCS’16, Neil Ghani, Fredrik Nordvall Forsberg, and Alex Simp-

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-

  • ry paper award for ETAPS]
slide-79
SLIDE 79

Extensions

  • At WoLLIC’15, Neil Ghani, Fredrik Nordvall Forsberg, and Federico

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

  • At FoSSaCS’16, Neil Ghani, Fredrik Nordvall Forsberg, and Alex Simp-

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-

  • ry paper award for ETAPS]
  • At WadlerFest, Neil Ghani, Fredrik Nordvall Forsberg, and Federico

Orsanigo developed a proof-relevant version of our framework

slide-80
SLIDE 80

Extensions

  • At WoLLIC’15, Neil Ghani, Fredrik Nordvall Forsberg, and Federico

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

  • At FoSSaCS’16, Neil Ghani, Fredrik Nordvall Forsberg, and Alex Simp-

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-

  • ry paper award for ETAPS]
  • At WadlerFest, Neil Ghani, Fredrik Nordvall Forsberg, and Federico

Orsanigo developed a proof-relevant version of our framework

  • Cl´

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)

slide-81
SLIDE 81

References

  • Functorial Polymorphism.

E.S. Bainbridge, P.J. Freyd, A. Scedrov, and P. Scott. Theoretical Computer Science, 1990. [Gives a functorial semantics of polymorphism]

  • Types, abstractions, and parametric polymorphism, part 2. Q. Ma and
  • J. Reynolds. MFPS’92 [Developed the first categorical framework for

parametric polymorphism (PL-categories)]

  • Categorical models for Abadi and Plotkin’s logic for parametricity. L.

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]

  • Parametric limits. B. Dunphy and U. Reddy. LICS’04. [First model

to mix fibrations with reflexive graphs, but obtains existence of initial algebras only for strictly positive functors]

  • And many, many more...