Taming Effects in a Dependent World Pierre-Marie Pdrot Max Planck - - PowerPoint PPT Presentation

taming effects in a dependent world
SMART_READER_LITE
LIVE PREVIEW

Taming Effects in a Dependent World Pierre-Marie Pdrot Max Planck - - PowerPoint PPT Presentation

. . . . . . . . . . . . . . . Taming Effects in a Dependent World Pierre-Marie Pdrot Max Planck Institute for Software Systems Journes Nationales Gocal-LAC 14th November 2017 P.-M. Pdrot (MPI-SWS) Taming efgects in a


slide-1
SLIDE 1

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Taming Effects in a Dependent World

Pierre-Marie Pédrot

Max Planck Institute for Software Systems

Journées Nationales Géocal-LAC

14th November 2017

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 1 / 38

slide-2
SLIDE 2

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

CIC: « Constructions dans un monde qui bouge » CIC, the Calculus of Inductive Constructions.

CIC, a very fancy intuitionistic logical system. Not just higher-order logic, not just fjrst-order logic First class notion of computation and crazy inductive types CIC, a very powerful functional programming language. Finest types to describe your programs No clear phase separation between runtime and compile time

The Pinnacle of the Curry-Howard correspondence

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 2 / 38

slide-3
SLIDE 3

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

CIC: « Constructions dans un monde qui bouge » CIC, the Calculus of Inductive Constructions.

CIC, a very fancy intuitionistic logical system. Not just higher-order logic, not just fjrst-order logic First class notion of computation and crazy inductive types CIC, a very powerful functional programming language. Finest types to describe your programs No clear phase separation between runtime and compile time

The Pinnacle of the Curry-Howard correspondence

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 2 / 38

slide-4
SLIDE 4

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

CIC: « Constructions dans un monde qui bouge » CIC, the Calculus of Inductive Constructions.

CIC, a very fancy intuitionistic logical system. Not just higher-order logic, not just fjrst-order logic First class notion of computation and crazy inductive types CIC, a very powerful functional programming language. Finest types to describe your programs No clear phase separation between runtime and compile time

The Pinnacle of the Curry-Howard correspondence

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 2 / 38

slide-5
SLIDE 5

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

CIC: « Constructions dans un monde qui bouge » CIC, the Calculus of Inductive Constructions.

CIC, a very fancy intuitionistic logical system. Not just higher-order logic, not just fjrst-order logic First class notion of computation and crazy inductive types CIC, a very powerful functional programming language. Finest types to describe your programs No clear phase separation between runtime and compile time

The Pinnacle of the Curry-Howard correspondence

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 2 / 38

slide-6
SLIDE 6

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

An Efgective Object One implementation to rule them all...

Many big developments using it for computer-checked proofs. Mathematics: Four colour theorem, Feit-Thompson, Unimath... Computer Science: CompCert, VST, RustBelt...

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 3 / 38

slide-7
SLIDE 7

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

An Efgective Object One implementation to rule them all...

Many big developments using it for computer-checked proofs. Mathematics: Four colour theorem, Feit-Thompson, Unimath... Computer Science: CompCert, VST, RustBelt...

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 3 / 38

slide-8
SLIDE 8

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

An Efgective Object One implementation to rule them all...

Many big developments using it for computer-checked proofs. Mathematics: Four colour theorem, Feit-Thompson, Unimath... Computer Science: CompCert, VST, RustBelt...

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 3 / 38

slide-9
SLIDE 9

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Most Important Issue of Them All Yet CIC sufgers from a fundamental fmaw.

You want to show the wonders of Coq to a fellow programmer You fjre your favourite IDE ... and you’re asked the dreadful question.

Could you write a Hello World program please?

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 4 / 38

slide-10
SLIDE 10

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Most Important Issue of Them All Yet CIC sufgers from a fundamental fmaw.

You want to show the wonders of Coq to a fellow programmer You fjre your favourite IDE ... and you’re asked the dreadful question.

Could you write a Hello World program please?

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 4 / 38

slide-11
SLIDE 11

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Most Important Issue of Them All Yet CIC sufgers from a fundamental fmaw.

You want to show the wonders of Coq to a fellow programmer You fjre your favourite IDE ... and you’re asked the dreadful question.

Could you write a Hello World program please?

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 4 / 38

slide-12
SLIDE 12

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Well-known Limitation

This is pretty much standard. By the Curry-Howard correspondence

Intuitionistic Logic ⇔ Functional Programming

That means no effects in CIC, amongst which: no exceptions, state, non-termination, printing... ... and thus no Hello World Dually, for the same reasons, no classical reasoning . Curry-Howard principle: efgects extend your logic.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 5 / 38

slide-13
SLIDE 13

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Well-known Limitation

This is pretty much standard. By the Curry-Howard correspondence

Intuitionistic Logic ⇔ Functional Programming

That means no effects in CIC, amongst which: no exceptions, state, non-termination, printing... ... and thus no Hello World Dually, for the same reasons, no classical reasoning . Curry-Howard principle: efgects extend your logic.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 5 / 38

slide-14
SLIDE 14

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Thesis We want a type theory with efgects!

1 To program more (exceptions, non-termination...) 2 To prove more (classical logic, univalence...) 3 To write Hello World.

It’s not just randomly coming up with typing rules though.

We want a model of type theory with efgects.

1 The theory ought to be logically consistent 2 It should be implementable (e.g. decidable type-checking) 3 Other nice properties like canonicity (

n implies n S S O)

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 6 / 38

slide-15
SLIDE 15

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Thesis We want a type theory with efgects!

1 To program more (exceptions, non-termination...) 2 To prove more (classical logic, univalence...) 3 To write Hello World.

It’s not just randomly coming up with typing rules though.

We want a model of type theory with efgects.

1 The theory ought to be logically consistent 2 It should be implementable (e.g. decidable type-checking) 3 Other nice properties like canonicity (

n implies n S S O)

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 6 / 38

slide-16
SLIDE 16

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Thesis We want a type theory with efgects!

1 To program more (exceptions, non-termination...) 2 To prove more (classical logic, univalence...) 3 To write Hello World.

It’s not just randomly coming up with typing rules though.

We want a model of type theory with efgects.

1 The theory ought to be logically consistent 2 It should be implementable (e.g. decidable type-checking) 3 Other nice properties like canonicity (⊢ n : N implies n ⇝ S . . . S O) P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 6 / 38

slide-17
SLIDE 17

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Aporias

Semantics of type theory have a fame of being horribly complex. I won’t lie: it is. But part of this fame is nonetheless due to its models. Set-theoretical models: because Sets are a (crappy) type theory.

Pro: Sets! Con: Sets!

Realizability models: construct programs that respect properties.

Pro: Computational, computer-science friendly. Con: Not foundational (requires an alien meta-theory), not decidable.

Categorical models: abstract description of type theory.

Pro: Abstract, subsumes the two former ones. Con: Realizability + very low level, gazillion variants, intrisically typed, static.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 7 / 38

slide-18
SLIDE 18

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Aporias

Semantics of type theory have a fame of being horribly complex. I won’t lie: it is. But part of this fame is nonetheless due to its models. Set-theoretical models: because Sets are a (crappy) type theory.

Pro: Sets! Con: Sets!

Realizability models: construct programs that respect properties.

Pro: Computational, computer-science friendly. Con: Not foundational (requires an alien meta-theory), not decidable.

Categorical models: abstract description of type theory.

Pro: Abstract, subsumes the two former ones. Con: Realizability + very low level, gazillion variants, intrisically typed, static.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 7 / 38

slide-19
SLIDE 19

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Aporias

Semantics of type theory have a fame of being horribly complex. I won’t lie: it is. But part of this fame is nonetheless due to its models. Set-theoretical models: because Sets are a (crappy) type theory.

Pro: Sets! Con: Sets!

Realizability models: construct programs that respect properties.

Pro: Computational, computer-science friendly. Con: Not foundational (requires an alien meta-theory), not decidable.

Categorical models: abstract description of type theory.

Pro: Abstract, subsumes the two former ones. Con: Realizability + very low level, gazillion variants, intrisically typed, static.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 7 / 38

slide-20
SLIDE 20

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Aporias

Semantics of type theory have a fame of being horribly complex. I won’t lie: it is. But part of this fame is nonetheless due to its models. Set-theoretical models: because Sets are a (crappy) type theory.

Pro: Sets! Con: Sets!

Realizability models: construct programs that respect properties.

Pro: Computational, computer-science friendly. Con: Not foundational (requires an alien meta-theory), not decidable.

Categorical models: abstract description of type theory.

Pro: Abstract, subsumes the two former ones. Con: Realizability + very low level, gazillion variants, intrisically typed, static.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 7 / 38

slide-21
SLIDE 21

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Aporias

Semantics of type theory have a fame of being horribly complex. I won’t lie: it is. But part of this fame is nonetheless due to its models. Set-theoretical models: because Sets are a (crappy) type theory.

Pro: Sets! Con: Sets!

Realizability models: construct programs that respect properties.

Pro: Computational, computer-science friendly. Con: Not foundational (requires an alien meta-theory), not decidable.

Categorical models: abstract description of type theory.

Pro: Abstract, subsumes the two former ones. Con: Realizability + very low level, gazillion variants, intrisically typed, static.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 7 / 38

slide-22
SLIDE 22

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Curry-Howard Orthodoxy

Instead, let’s look at what Curry-Howard provides in simpler settings.

Logical Interpretations ⇔ Program Translations

On the programming side, implement efgects using e.g. the monadic style. A type transformer T, two combinators, a few equations Interpret mechanically efgectful programs (e.g. in Haskell) On the logic side, extend expressivity through proof translation. Double-negation classical logic (callcc) Friedman’s trick Markov’s rule (exceptions) Forcing CH (global monotonous cell)

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 8 / 38

slide-23
SLIDE 23

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Curry-Howard Orthodoxy

Instead, let’s look at what Curry-Howard provides in simpler settings.

Logical Interpretations ⇔ Program Translations

On the programming side, implement efgects using e.g. the monadic style. A type transformer T, two combinators, a few equations Interpret mechanically efgectful programs (e.g. in Haskell) On the logic side, extend expressivity through proof translation. Double-negation classical logic (callcc) Friedman’s trick Markov’s rule (exceptions) Forcing CH (global monotonous cell)

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 8 / 38

slide-24
SLIDE 24

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Curry-Howard Orthodoxy

Instead, let’s look at what Curry-Howard provides in simpler settings.

Logical Interpretations ⇔ Program Translations

On the programming side, implement efgects using e.g. the monadic style. A type transformer T, two combinators, a few equations Interpret mechanically efgectful programs (e.g. in Haskell) On the logic side, extend expressivity through proof translation. Double-negation ⇒ classical logic (callcc) Friedman’s trick ⇒ Markov’s rule (exceptions) Forcing ⇒ ¬CH (global monotonous cell)

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 8 / 38

slide-25
SLIDE 25

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Syntactic Models

Let us do the same thing with CIC: build syntactic models. We take the following act of faith for granted.

CIC is.

Not caring for its soundness, implementation, whatever. It just is. Do everything by interpreting the new theories relatively to this foundation! Suppress technical and cognitive burden by lowering impedance mismatch.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 9 / 38

slide-26
SLIDE 26

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Syntactic Models

Let us do the same thing with CIC: build syntactic models. We take the following act of faith for granted.

CIC is.

Not caring for its soundness, implementation, whatever. It just is. Do everything by interpreting the new theories relatively to this foundation! Suppress technical and cognitive burden by lowering impedance mismatch.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 9 / 38

slide-27
SLIDE 27

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Syntactic Models

Let us do the same thing with CIC: build syntactic models. We take the following act of faith for granted.

CIC is.

Not caring for its soundness, implementation, whatever. It just is. Do everything by interpreting the new theories relatively to this foundation! Suppress technical and cognitive burden by lowering impedance mismatch.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 9 / 38

slide-28
SLIDE 28

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Syntactic Models II

Step 0: Fix a theory T as close as possible to CIC, ideally CIC ⊆ T . Step 1: Defjne

  • n the syntax of

and derive from it s.t. M A implies

CIC M

A Step 2: Flip views and actually pose M A

CIC M

A Step 3: Expand by going down to the CIC assembly language, implementing new terms given by the translation.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 10 / 38

slide-29
SLIDE 29

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Syntactic Models II

Step 0: Fix a theory T as close as possible to CIC, ideally CIC ⊆ T . Step 1: Defjne [·] on the syntax of T and derive [ [·] ] from it s.t. ⊢T M : A implies ⊢CIC [M] : [ [A] ] Step 2: Flip views and actually pose M A

CIC M

A Step 3: Expand by going down to the CIC assembly language, implementing new terms given by the translation.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 10 / 38

slide-30
SLIDE 30

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Syntactic Models II

Step 0: Fix a theory T as close as possible to CIC, ideally CIC ⊆ T . Step 1: Defjne [·] on the syntax of T and derive [ [·] ] from it s.t. ⊢T M : A implies ⊢CIC [M] : [ [A] ] Step 2: Flip views and actually pose ⊢T M : A

= ⊢CIC [M] : [ [A] ] Step 3: Expand by going down to the CIC assembly language, implementing new terms given by the translation.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 10 / 38

slide-31
SLIDE 31

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Syntactic Models II

Step 0: Fix a theory T as close as possible to CIC, ideally CIC ⊆ T . Step 1: Defjne [·] on the syntax of T and derive [ [·] ] from it s.t. ⊢T M : A implies ⊢CIC [M] : [ [A] ] Step 2: Flip views and actually pose ⊢T M : A

= ⊢CIC [M] : [ [A] ] Step 3: Expand T by going down to the CIC assembly language, implementing new terms given by the [·] translation.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 10 / 38

slide-32
SLIDE 32

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

« CIC, the LLVM of Type Theory »

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 11 / 38

slide-33
SLIDE 33

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Syntactic Models III

Obviously, that’s subtle. If you want CIC ⊆ T , The translation must preserve typing (not easy) In particular, it must preserve conversion (stay tuned) Yet, a lot of nice consequences. Does not require non-type-theoretical foundations (monism) Can be implemented in Coq (software monism) Easy to show (relative) consistency, look at False Inherit properties from CIC: computationality, decidability...

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 12 / 38

slide-34
SLIDE 34

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Syntactic Models III

Obviously, that’s subtle. If you want CIC ⊆ T , The translation must preserve typing (not easy) In particular, it must preserve conversion (stay tuned) Yet, a lot of nice consequences. Does not require non-type-theoretical foundations (monism) Can be implemented in Coq (software monism) Easy to show (relative) consistency, look at [ [False] ] Inherit properties from CIC: computationality, decidability...

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 12 / 38

slide-35
SLIDE 35

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Conversion

Dependency entails one major difgerence with usual program translations. Meet conversion: A B M B M A Bad news 1

Typing rules embed the dynamics of programs!

Combine that with this other observation and we’re in trouble. Bad news 2

Efgects make reduction strategies relevant.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 13 / 38

slide-36
SLIDE 36

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Conversion

Dependency entails one major difgerence with usual program translations. Meet conversion: A ≡β B Γ ⊢ M : B Γ ⊢ M : A Bad news 1

Typing rules embed the dynamics of programs!

Combine that with this other observation and we’re in trouble. Bad news 2

Efgects make reduction strategies relevant.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 13 / 38

slide-37
SLIDE 37

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Conversion

Dependency entails one major difgerence with usual program translations. Meet conversion: A ≡β B Γ ⊢ M : B Γ ⊢ M : A Bad news 1

Typing rules embed the dynamics of programs!

Combine that with this other observation and we’re in trouble. Bad news 2

Efgects make reduction strategies relevant.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 13 / 38

slide-38
SLIDE 38

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Conversion

Dependency entails one major difgerence with usual program translations. Meet conversion: A ≡β B Γ ⊢ M : B Γ ⊢ M : A Bad news 1

Typing rules embed the dynamics of programs!

Combine that with this other observation and we’re in trouble. Bad news 2

Efgects make reduction strategies relevant.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 13 / 38

slide-39
SLIDE 39

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Though Choice

We have two canonical possibilities in presence of efgects. Call-by-value Call-by-name

Usual monadic decomposition Understandable semantics Values still enjoy canonicity Good old ML More complex model (CBPV) Counter-intuitive behaviours Jeopardizes canonicity WTF PLT?

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 14 / 38

slide-40
SLIDE 40

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Though Choice

We have two canonical possibilities in presence of efgects. Call-by-value Call-by-name

Usual monadic decomposition Understandable semantics Values still enjoy canonicity Good old ML More complex model (CBPV) Counter-intuitive behaviours Jeopardizes canonicity WTF PLT?

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 14 / 38

slide-41
SLIDE 41

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Problem I

Recall conversion:

A ≡β B

Γ ⊢ M : B Γ ⊢ M : A In case you forgot your glasses:

CIC has an CBN equational theory.

It’s unclear what you can do with CBV dependency... ... and probably type terrorists will start crying foul and calling it heresy.

So we have to stick to CBN to please the conservative reviewers.

(But see e.g. comrade Lepigre’s agitprop challenging the bourgeois proof theory.)

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 15 / 38

slide-42
SLIDE 42

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Problem I

Recall conversion:

A ≡β B

Γ ⊢ M : B Γ ⊢ M : A In case you forgot your glasses:

CIC has an CBN equational theory.

It’s unclear what you can do with CBV dependency... ... and probably type terrorists will start crying foul and calling it heresy.

So we have to stick to CBN to please the conservative reviewers.

(But see e.g. comrade Lepigre’s agitprop challenging the bourgeois proof theory.)

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 15 / 38

slide-43
SLIDE 43

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Problem I

Recall conversion:

A ≡β B

Γ ⊢ M : B Γ ⊢ M : A In case you forgot your glasses:

CIC has an CBN equational theory.

It’s unclear what you can do with CBV dependency... ... and probably type terrorists will start crying foul and calling it heresy.

So we have to stick to CBN to please the conservative reviewers.

(But see e.g. comrade Lepigre’s agitprop challenging the bourgeois proof theory.)

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 15 / 38

slide-44
SLIDE 44

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Problem II

Assuming rightly I don’t care about peer pressure, we have another issue.

Monadic encodings don’t scale to dependent types.

The reason lies in the typing of bind: bind T A A T B T B It’s seemingly not possible to adapt it to the dependent case! dbind x T A x A T B x T B Meanwhile, CBPV naturally extends to dependent types.

We also have to stick to CBN for technical reasons.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 16 / 38

slide-45
SLIDE 45

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Problem II

Assuming rightly I don’t care about peer pressure, we have another issue.

Monadic encodings don’t scale to dependent types.

The reason lies in the typing of bind: bind T A A T B T B It’s seemingly not possible to adapt it to the dependent case! dbind x T A x A T B x T B Meanwhile, CBPV naturally extends to dependent types.

We also have to stick to CBN for technical reasons.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 16 / 38

slide-46
SLIDE 46

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Problem II

Assuming rightly I don’t care about peer pressure, we have another issue.

Monadic encodings don’t scale to dependent types.

The reason lies in the typing of bind: bind : T A → (A → T B) → T B. It’s seemingly not possible to adapt it to the dependent case! dbind : Π(ˆ x : T A). (Π(x : A).T (B x)) → T (B ?). Meanwhile, CBPV naturally extends to dependent types.

We also have to stick to CBN for technical reasons.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 16 / 38

slide-47
SLIDE 47

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Life is Life

Like Homer, we’re dragged to the horrible CBN side against our will. Come on, what could possibly go wronger?

Dependent elimination + CBN efgects inconsistency.

This is the internal counterpart of the lack of canonicity.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 17 / 38

slide-48
SLIDE 48

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Life is Life

Like Homer, we’re dragged to the horrible CBN side against our will. Come on, what could possibly go wronger?

Dependent elimination + CBN efgects ⇒ inconsistency.

This is the internal counterpart of the lack of canonicity.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 17 / 38

slide-49
SLIDE 49

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Reduction vs. Efgects

Call-by-name: functions well-behaved vs. inductives ill-behaved Call-by-value: inductives well-behaved vs. functions ill-behaved Why is that? In call-by-name + efgects: x M N M x N arbitrary substitution b bool M fail non-standard booleans In call-by-value + efgects: x M V M x V substitute only values b unit fail b invalid

  • rule

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 18 / 38

slide-50
SLIDE 50

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Reduction vs. Efgects

Call-by-name: functions well-behaved vs. inductives ill-behaved Call-by-value: inductives well-behaved vs. functions ill-behaved Why is that? In call-by-name + efgects: (λx. M) N ≡ M{x := N} ⇝ arbitrary substitution (λb : bool. M) fail ⇝ non-standard booleans In call-by-value + efgects: (λx. M) V ≡ M{x := V} ⇝ substitute only values (λb : unit. fail b) ⇝ invalid η-rule

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 18 / 38

slide-51
SLIDE 51

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Eliminating Addiction to Dependence

Recall that dependent elimination is just the induction principle. For instance, on the boolean type: Γ ⊢ M : B Γ ⊢ N1 : P{b := true} Γ ⊢ N2 : P{b := false} Γ ⊢ if M then N1 else N2 : P{b := M} This is a statement refmecting canonicity as an internal property in CIC. But there are efgectful closed booleans which are neither true nor false...

Dependent elimination is hardcore intuitionistic.

It makes a very strong assumption about the universe of discourse. Note also that dependent elimination on

  • types implies AC...

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 19 / 38

slide-52
SLIDE 52

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Eliminating Addiction to Dependence

Recall that dependent elimination is just the induction principle. For instance, on the boolean type: Γ ⊢ M : B Γ ⊢ N1 : P{b := true} Γ ⊢ N2 : P{b := false} Γ ⊢ if M then N1 else N2 : P{b := M} This is a statement refmecting canonicity as an internal property in CIC. But there are efgectful closed booleans which are neither true nor false...

Dependent elimination is hardcore intuitionistic.

It makes a very strong assumption about the universe of discourse. Note also that dependent elimination on Σ-types implies AC...

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 19 / 38

slide-53
SLIDE 53

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

If there is no solution, there is no problem Dependent elimination + CBN efgects ⇒ inconsistency. Two Easy Ways Out!

1 Embrace inconsistency: truth is a totally overrated social construct. 2 Get into rehab: weaken dependent elimination for a linear fjx.

In the remaining of this talk, we will have a look at one instance of each case, namely exceptions and read-only cells.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 20 / 38

slide-54
SLIDE 54

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

If there is no solution, there is no problem Dependent elimination + CBN efgects ⇒ inconsistency. Two Easy Ways Out!

1 Embrace inconsistency: truth is a totally overrated social construct. 2 Get into rehab: weaken dependent elimination for a linear fjx.

In the remaining of this talk, we will have a look at one instance of each case, namely exceptions and read-only cells.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 20 / 38

slide-55
SLIDE 55

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

That’s literally what we are going to do.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 21 / 38

slide-56
SLIDE 56

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

That’s literally what we are going to do.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 21 / 38

slide-57
SLIDE 57

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Exceptional Translation

Assume some fjxed type of exceptions E. The exceptional translation extends CIC with raiseA : E → A for any A catchA : A → A + E for a few specifjc A satisfying a few expected defjnitional equations. CBN catching exceptions is limited to positive datatypes (inductive). In particular, by

  • expansion, raise

x A B e

x A raiseB e.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 22 / 38

slide-58
SLIDE 58

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Exceptional Translation

Assume some fjxed type of exceptions E. The exceptional translation extends CIC with raiseA : E → A for any A catchA : A → A + E for a few specifjc A satisfying a few expected defjnitional equations. CBN ⇝ catching exceptions is limited to positive datatypes (inductive). In particular, by η-expansion, raise(Πx:A. B) e ≡β λx : A. raiseB e.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 22 / 38

slide-59
SLIDE 59

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Exceptional Implementation, Negative case

Intuitive idea: translate every A : □ into [A] : ΣA : □. E → A. [ [A] ] : □ := π1 [A] and [A]∅ : E → [ [A] ] := π2 [A] Because CBN, trivial on the negative fragment: x A B x A B x A B e x A B e x x M N M N x A M x A M

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 23 / 38

slide-60
SLIDE 60

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Exceptional Implementation, Negative case

Intuitive idea: translate every A : □ into [A] : ΣA : □. E → A. [ [A] ] : □ := π1 [A] and [A]∅ : E → [ [A] ] := π2 [A] Because CBN, trivial on the negative fragment: [ [Πx : A. B] ] ≡ Πx : [ [A] ]. [ [B] ] [Πx : A. B]∅ e ≡ λx : [ [A] ]. [B]∅ e [x] ≡ x [M N] ≡ [M] [N] [λx : A. M] ≡ λx : [ [A] ]. [M]

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 23 / 38

slide-61
SLIDE 61

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Exceptional Implementation, Positive case

The really interesting case is the inductive part of CIC. How to implement e.g. [B]∅ : E → [ [B] ]? Or worse [⊥]∅ : E → [ [⊥] ]? Very simple: add a default case to every inductive type! Inductive true false Pattern-matching is translated pointwise, except for the new case. P P true P false b P b P P true P false b P b If b is true , use fjrst hypothesis If b is false , use second hypothesis If b is an error e, reraise e using P b e

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 24 / 38

slide-62
SLIDE 62

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Exceptional Implementation, Positive case

The really interesting case is the inductive part of CIC. How to implement e.g. [B]∅ : E → [ [B] ]? Or worse [⊥]∅ : E → [ [⊥] ]? Very simple: add a default case to every inductive type! Inductive [ [B] ] := [true] : [ [B] ] | [false] : [ [B] ] | B∅ : E → [ [B] ] Pattern-matching is translated pointwise, except for the new case. P P true P false b P b P P true P false b P b If b is true , use fjrst hypothesis If b is false , use second hypothesis If b is an error e, reraise e using P b e

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 24 / 38

slide-63
SLIDE 63

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Exceptional Implementation, Positive case

The really interesting case is the inductive part of CIC. How to implement e.g. [B]∅ : E → [ [B] ]? Or worse [⊥]∅ : E → [ [⊥] ]? Very simple: add a default case to every inductive type! Inductive [ [B] ] := [true] : [ [B] ] | [false] : [ [B] ] | B∅ : E → [ [B] ] Pattern-matching is translated pointwise, except for the new case. [ [ΠP : B → □. P true → P false → Πb : B. P b] ] ∼ = ΠP : [ [B] ] → [ [□] ]. P [true] → P [false] → Πb : [ [B] ]. P b If b is [true], use fjrst hypothesis If b is [false], use second hypothesis If b is an error B∅ e, reraise e using [P b]∅ e

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 24 / 38

slide-64
SLIDE 64

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Time to complain

This gives a syntactic model of all CIC. Every type is inhabited by and thus the theory is inconsistent!

Still usable for programming. Do you whine about OCaml’s exceptions? Plus you can use the target CIC to reason on your efgectful programs. Further interest: classical proof extraction. Indeed: A A Allows to prove the following CIC equivalent of Friedman’s trick. Conservativity of classical reasoning on formulae in CIC If P and Q are fjrst-order types,

CIC

p P Q implies

CIC

p P Q.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 25 / 38

slide-65
SLIDE 65

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Time to complain

This gives a syntactic model of all CIC. Every type is inhabited by [·]∅ and thus the theory is inconsistent!

Still usable for programming. Do you whine about OCaml’s exceptions? Plus you can use the target CIC to reason on your efgectful programs. Further interest: classical proof extraction. Indeed: A A Allows to prove the following CIC equivalent of Friedman’s trick. Conservativity of classical reasoning on formulae in CIC If P and Q are fjrst-order types,

CIC

p P Q implies

CIC

p P Q.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 25 / 38

slide-66
SLIDE 66

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Time to complain

This gives a syntactic model of all CIC. Every type is inhabited by [·]∅ and thus the theory is inconsistent!

Still usable for programming. Do you whine about OCaml’s exceptions? Plus you can use the target CIC to reason on your efgectful programs. Further interest: classical proof extraction. Indeed: A A Allows to prove the following CIC equivalent of Friedman’s trick. Conservativity of classical reasoning on formulae in CIC If P and Q are fjrst-order types,

CIC

p P Q implies

CIC

p P Q.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 25 / 38

slide-67
SLIDE 67

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Time to complain

This gives a syntactic model of all CIC. Every type is inhabited by [·]∅ and thus the theory is inconsistent!

Still usable for programming. Do you whine about OCaml’s exceptions? Plus you can use the target CIC to reason on your efgectful programs. Further interest: classical proof extraction. Indeed: [ [¬¬A] ] ∼ = ([ [A] ] → E) → E Allows to prove the following CIC equivalent of Friedman’s trick. Conservativity of classical reasoning on Π2

0 formulae in CIC

If P and Q are fjrst-order types, ⊢CIC Πp : P. ¬¬Q implies ⊢CIC Πp : P. Q.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 25 / 38

slide-68
SLIDE 68

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Recovering Consistency

Actually, one can use Bernardy-Lasson parametricity to recover consistency. Intuition: in addition to [M] : [ [A] ], produce [M]ε : [ [A] ]ε [M] where [ [A] ]ε encodes the fact that [M] does not generate uncaught exceptions, e.g. [ [Πx : A. B] ]ε f ≡ Πx : [ [A] ]. [ [A] ]ε x → [ [B] ]ε (f x) But you still have the right to use exceptions locally!

This is exactly Kreisel’s realizability for CIC.

There is a syntactic model of CIC that proves independence of premise (IP): A P A n P n n A P n which is consistent, enjoys canonicity and has decidable type-checking.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 26 / 38

slide-69
SLIDE 69

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Recovering Consistency

Actually, one can use Bernardy-Lasson parametricity to recover consistency. Intuition: in addition to [M] : [ [A] ], produce [M]ε : [ [A] ]ε [M] where [ [A] ]ε encodes the fact that [M] does not generate uncaught exceptions, e.g. [ [Πx : A. B] ]ε f ≡ Πx : [ [A] ]. [ [A] ]ε x → [ [B] ]ε (f x) But you still have the right to use exceptions locally!

This is exactly Kreisel’s realizability for CIC.

There is a syntactic model of CIC that proves independence of premise (IP): A P A n P n n A P n which is consistent, enjoys canonicity and has decidable type-checking.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 26 / 38

slide-70
SLIDE 70

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Recovering Consistency

Actually, one can use Bernardy-Lasson parametricity to recover consistency. Intuition: in addition to [M] : [ [A] ], produce [M]ε : [ [A] ]ε [M] where [ [A] ]ε encodes the fact that [M] does not generate uncaught exceptions, e.g. [ [Πx : A. B] ]ε f ≡ Πx : [ [A] ]. [ [A] ]ε x → [ [B] ]ε (f x) But you still have the right to use exceptions locally!

This is exactly Kreisel’s realizability for CIC.

There is a syntactic model of CIC that proves independence of premise (IP): Π(A : □) (P : N → □). (¬A → Σn : N. P n) → Σn : N. ¬A → P n which is consistent, enjoys canonicity and has decidable type-checking.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 26 / 38

slide-71
SLIDE 71

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The reader translation, a.k.a. Baby Forcing

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 27 / 38

slide-72
SLIDE 72

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Reader Translation

Assume some fjxed cell type R. The reader translation extends type theory with read : R into : □ → R → □ enterA : A → Πr : R. into A r satisfying a few expected defjnitional equations. The into function has unfoldings on type formers: into x A B r x A into B r into A r A for positive A and it is somewhat redundant: enter A r into A r

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 28 / 38

slide-73
SLIDE 73

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Reader Translation

Assume some fjxed cell type R. The reader translation extends type theory with read : R into : □ → R → □ enterA : A → Πr : R. into A r satisfying a few expected defjnitional equations. The into function has unfoldings on type formers: into (Πx : A. B) r ≡ Πx : A. into B r into A r ≡ A for positive A and it is somewhat redundant: enter□ A r ≡ into A r

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 28 / 38

slide-74
SLIDE 74

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Reader Implementation

Assuming r : R, intuitively: Translate A : □ into [A]r : □ Translate M : A into [M]r : [A]r On the other side of the CBPV adjunction:

r

x A B r x s A s B r x r x r M N r M r s N s x A M r x s A s M r

All variables are thunked w.r.t. !

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 29 / 38

slide-75
SLIDE 75

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Reader Implementation

Assuming r : R, intuitively: Translate A : □ into [A]r : □ Translate M : A into [M]r : [A]r On the other side of the CBPV adjunction: [□]r ≡ □ [Πx : A. B]r ≡ Πx : (Πs : R. [A]s). [B]r [x]r ≡ x r [M N]r ≡ [M]r (λs : R. [N]s) [λx : A. M]r ≡ λx : (Πs : R. [A]s). [M]r

All variables are thunked w.r.t. R!

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 29 / 38

slide-76
SLIDE 76

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Reader Implementation: Inductive Types

PLT tells us we have to take [B]r ≡ B. It’s possible to implement non-dependent pattern matching as usual. Preserves defjnitional computation rules But it’s not possible to implement dependent pattern matching! P P true P false b P b r P s P s _ true s P s _ false b P r b P only holds for two specifjc values but b can be anything! We cannot even test in general that b is extensionally one of those values.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 30 / 38

slide-77
SLIDE 77

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The Reader Implementation: Inductive Types

PLT tells us we have to take [B]r ≡ B. It’s possible to implement non-dependent pattern matching as usual. Preserves defjnitional computation rules But it’s not possible to implement dependent pattern matching! [ [ΠP : B → □. P true → P false → Πb : B. P b] ]r ≡ ΠP : R → (R → B) → □. (Πs : R. P s (λ _ : R. true)) → (Πs : R. P s (λ _ : R. false)) → Πb : R → B. P r b P only holds for two specifjc values but b : R → B can be anything! We cannot even test in general that b is extensionally one of those values.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 30 / 38

slide-78
SLIDE 78

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Not All Predicates are Equal

For certain predicates P : R → (R → B) → □, induction still valid though. Indeed, if P r b r b r for some , the induction principle becomes s s true s s false b r b r which is provable by case-analysis on b r. Such predicates evaluate « immediately » their argument b. They only rely on the resulting value! This property is completely independent from the reader efgect.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 31 / 38

slide-79
SLIDE 79

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Not All Predicates are Equal

For certain predicates P : R → (R → B) → □, induction still valid though. Indeed, if P r b ≡ Φ r (b r) for some Φ, the induction principle becomes (Πs : R. Φ s true) → (Πs : R. Φ s false) → Πb : R → B. Φ r (b r) which is provable by case-analysis on b r. Such predicates evaluate « immediately » their argument b. They only rely on the resulting value! This property is completely independent from the reader efgect.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 31 / 38

slide-80
SLIDE 80

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Not All Predicates are Equal

For certain predicates P : R → (R → B) → □, induction still valid though. Indeed, if P r b ≡ Φ r (b r) for some Φ, the induction principle becomes (Πs : R. Φ s true) → (Πs : R. Φ s false) → Πb : R → B. Φ r (b r) which is provable by case-analysis on b r. Such predicates evaluate « immediately » their argument b. They only rely on the resulting value! This property is completely independent from the reader efgect.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 31 / 38

slide-81
SLIDE 81

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Moi, j'ai dit linéaire, linéaire ? Comme c'est étrange...

Actually we have a generic semantic criterion for valid predicates.

LINEARITY.

Courtesy of G. Munch, rephrased recently by P. Levy. Little to do with « linear use of variables » Although tightly linked to linear logic

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 32 / 38

slide-82
SLIDE 82

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Moi, j'ai dit linéaire, linéaire ? Comme c'est étrange...

Actually we have a generic semantic criterion for valid predicates.

LINEARITY.

Courtesy of G. Munch, rephrased recently by P. Levy. Little to do with « linear use of variables » Although tightly linked to linear logic

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 32 / 38

slide-83
SLIDE 83

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Linearity in a Nutshell

Defjned as an (undecidable) equational property of CBN functions. A function f : A → B is linear in A if for all ˆ x : box A, f (match ˆ x with Box x ⇒ x) ≡ match ˆ x with Box x ⇒ f x where Inductive box A := Box : A → box A. A CBN f A B is linear in A if semantically CBV in A. Categorically, f linear ifg it is an algebra morphism. In a pure language, all functions are linear!

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 33 / 38

slide-84
SLIDE 84

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Linearity in a Nutshell

Defjned as an (undecidable) equational property of CBN functions. A function f : A → B is linear in A if for all ˆ x : box A, f (match ˆ x with Box x ⇒ x) ≡ match ˆ x with Box x ⇒ f x where Inductive box A := Box : A → box A. A CBN f : A → B is linear in A if semantically CBV in A. Categorically, f linear ifg it is an algebra morphism. In a pure language, all functions are linear!

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 33 / 38

slide-85
SLIDE 85

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Linear Dependence is All You Need

We restrict dependent elimination in the following way: Γ ⊢ M : B . . . P linear in b Γ ⊢ if M then N1 else N2 : P{b := M} Can be underapproximated by a syntactic criterion A new kind of guard condition in CIC The CBN doppelgänger of the dreaded value restriction in CBV! Every predicate can be freely made linear thanks to storage operators

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 34 / 38

slide-86
SLIDE 86

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Bishop-style Type Theory

We can generalize this restriction to form Baclofen Type Theory. Strict subset of CIC Works with our forcing translation (LICS 2016) Works with our weaning translation (LICS 2017) Prevents Herbelin’s paradox: CIC + callcc inconsistent

BTT is the generic theory to deal with dependent efgects « Bishop-style, efgect-agnostic type theory »

(Take that, Brouwerian HoTT!)

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 35 / 38

slide-87
SLIDE 87

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

A Bishop-style Type Theory

We can generalize this restriction to form Baclofen Type Theory. Strict subset of CIC Works with our forcing translation (LICS 2016) Works with our weaning translation (LICS 2017) Prevents Herbelin’s paradox: CIC + callcc inconsistent

BTT is the generic theory to deal with dependent efgects « Bishop-style, efgect-agnostic type theory »

(Take that, Brouwerian HoTT!)

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 35 / 38

slide-88
SLIDE 88

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Implementations

Thanks to the fact we build syntactic models, we can implement them in Coq through a plugin.

https://github.com/CoqHott/coq-effects https://github.com/CoqHott/exceptional-tt

Allows to add efgects to Coq just today. Implement your favourite efgectful operators... Compile efgectful terms on the fmy. Allows to reason about them in Coq.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 36 / 38

slide-89
SLIDE 89

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Conclusion

Efgects and dependency: not that complicated if sticking to CBN.

But a trade-ofg about dependent elimination Inconsistency vs. linear dependent elimination

Even inconsistent theories have practical interest.

Exceptions enlarge the dynamic behaviour of your proofs Provide an unsafe hatch that can be used in a safe context

An experimentally confjrmed notion of efgectful type theories, BTT

Works for forcing, weaning (and callcc?) Restriction of dependent elimination on linearity guard condition Conjecture: the correct way to add efgects to TT

Implementation of plugins in Coq: try it out.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 37 / 38

slide-90
SLIDE 90

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Scribitur ad narrandum, non ad probandum

Thanks for your attention.

P.-M. Pédrot (MPI-SWS) Taming efgects in a dependent world 14/11/2017 38 / 38