An Efgectful Way to Eliminate Addiction to Dependence Pierre-Marie - - PowerPoint PPT Presentation

an efgectful way to eliminate addiction to dependence
SMART_READER_LITE
LIVE PREVIEW

An Efgectful Way to Eliminate Addiction to Dependence Pierre-Marie - - PowerPoint PPT Presentation

. . . . . . . . . . . . . . . An Efgectful Way to Eliminate Addiction to Dependence Pierre-Marie Pdrot 1 Nicolas Tabareau 2 EUTYPES / SSTT 31th January 2017 Pdrot & al. (U. Ljubljana & INRIA) An Efgectful Way


slide-1
SLIDE 1

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

An Efgectful Way to Eliminate Addiction to Dependence

Pierre-Marie Pédrot1 Nicolas Tabareau2

1University of Ljubljana, 2INRIA

EUTYPES / SSTT 31th January 2017

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 1 / 27

slide-2
SLIDE 2

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

The Most Important Issue of Them All

Let's start this talk by a fundamental fmaw of type theory. Assume 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édrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 2 / 27

slide-3
SLIDE 3

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

The Most Important Issue of Them All

Let's start this talk by a fundamental fmaw of type theory. Assume 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édrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 2 / 27

slide-4
SLIDE 4

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

The Most Important Issue of Them All

Let's start this talk by a fundamental fmaw of type theory. Assume 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édrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 2 / 27

slide-5
SLIDE 5

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

A Well-known Limitation

This is pretty much standard. By proof-as-program correspondence,

Intuitionistic Logic ⇔ Functional Programming

which means no efgects in TT, amongst which: no exceptions no state no non-termination no printing ... and thus no Hello World!

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 3 / 27

slide-6
SLIDE 6

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

A Well-known Limitation

This is pretty much standard. By proof-as-program correspondence,

Intuitionistic Logic ⇔ Functional Programming

which means no efgects in TT, amongst which: no exceptions no state no non-termination no printing ... and thus no Hello World!

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 3 / 27

slide-7
SLIDE 7

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

A Well-known Limitation

This is pretty much standard. By proof-as-program correspondence,

Intuitionistic Logic ⇔ Functional Programming

which means no efgects in TT, amongst which: no exceptions no state no non-termination no printing ... and thus no Hello World!

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 3 / 27

slide-8
SLIDE 8

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

On Burritos

In less expressive settings, a few workarounds are known. Typically, on the programming side, use the monadic style. A type T : □ → □ A combinator return : α → T α A combinator bind : T α → (α → T β) → T β A few equations Interpret mechanically efgectful programs using this (see Moggi). This is pervasive in e.g. Haskell.

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 4 / 27

slide-9
SLIDE 9

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

On Burritos

In less expressive settings, a few workarounds are known. Typically, on the programming side, use the monadic style. A type T : □ → □ A combinator return : α → T α A combinator bind : T α → (α → T β) → T β A few equations Interpret mechanically efgectful programs using this (see Moggi). This is pervasive in e.g. Haskell.

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 4 / 27

slide-10
SLIDE 10

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

Less is More

On the logic side, take the issue the other way around. Efgects are known to implement non-intuitionistic axioms! callcc classical logic (Griffjn '90) exceptions Markov's rule (Friedman's trick) global monotonous cell CH (forcing) delimited continuations double negation shift … Achieve this using logical translations, e.g. double-negation.

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 5 / 27

slide-11
SLIDE 11

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

Less is More

On the logic side, take the issue the other way around. Efgects are known to implement non-intuitionistic axioms! callcc ∼ classical logic (Griffjn '90) exceptions ∼ Markov's rule (Friedman's trick) global monotonous cell ∼ ¬CH (forcing) delimited continuations ∼ double negation shift … Achieve this using logical translations, e.g. double-negation.

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 5 / 27

slide-12
SLIDE 12

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

Alternative Facts 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. Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 6 / 27

slide-13
SLIDE 13

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

Alternative Facts 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. Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 6 / 27

slide-14
SLIDE 14

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

The Expressivity Wall

Problem is: Programming and logical techniques do not scale to type theory. Monads do not aknowledge dependence bind T T T dbind x T x T x T They don't aknowledge types-as-terms either And they don't preserve the computational rules of TT On the other hand: Herbelin showed that CIC + callcc is unsound!

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 7 / 27

slide-15
SLIDE 15

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

The Expressivity Wall

Problem is: Programming and logical techniques do not scale to type theory. Monads do not aknowledge dependence bind : T α → (α → T β) → T β dbind : Πˆ x : T α. (Πx : α. T (β x)) → T (β ?) They don't aknowledge types-as-terms either And they don't preserve the computational rules of TT On the other hand: Herbelin showed that CIC + callcc is unsound!

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 7 / 27

slide-16
SLIDE 16

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

The Expressivity Wall

Problem is: Programming and logical techniques do not scale to type theory. Monads do not aknowledge dependence bind : T α → (α → T β) → T β dbind : Πˆ x : T α. (Πx : α. T (β x)) → T (β ?) They don't aknowledge types-as-terms either And they don't preserve the computational rules of TT On the other hand: Herbelin showed that CIC + callcc is unsound!

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 7 / 27

slide-17
SLIDE 17

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

In This Talk

1 Adding a vast range of efgects to (almost) full TT

reader (already done previously with the forcing translation) writer, exceptions, non-termination, non-determinism... All with the new weaning translation!

2 Implementing them thanks to program translations

No crazy category theory models! So-called syntactic models. Compile them on-the-fmy into vanilla type theory!

3 Introducing a generic notion of efgectful dependent type theory

A simple, sensible restriction of dependent elimination Seemingly compatible with all known efgects

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 8 / 27

slide-18
SLIDE 18

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

In This Talk

1 Adding a vast range of efgects to (almost) full TT

reader (already done previously with the forcing translation) writer, exceptions, non-termination, non-determinism... All with the new weaning translation!

2 Implementing them thanks to program translations

No crazy category theory models! So-called syntactic models. Compile them on-the-fmy into vanilla type theory!

3 Introducing a generic notion of efgectful dependent type theory

A simple, sensible restriction of dependent elimination Seemingly compatible with all known efgects

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 8 / 27

slide-19
SLIDE 19

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

In This Talk

1 Adding a vast range of efgects to (almost) full TT

reader (already done previously with the forcing translation) writer, exceptions, non-termination, non-determinism... All with the new weaning translation!

2 Implementing them thanks to program translations

No crazy category theory models! So-called syntactic models. Compile them on-the-fmy into vanilla type theory!

3 Introducing a generic notion of efgectful dependent type theory

A simple, sensible restriction of dependent elimination Seemingly compatible with all known efgects

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 8 / 27

slide-20
SLIDE 20

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

Syntactic Models

Defjne [·] on the syntax and derive the type interpretation [ [·] ] from it s.t. ⊢ M : A implies ⊢ [M] : [ [A] ] Obviously, that's subtle. The correctness of lies in the meta (Darn, Gödel!) The translation must preserve typing (Not easy) In particular, it must preserve conversion (Argh!) Yet, a lot of nice consequences. Does not require non-type-theoretical foundations (monism) Can be implemented in your favourite proof assistant Easy to show (relative) consistency, look at False Easier to understand computationally

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 9 / 27

slide-21
SLIDE 21

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

Syntactic Models

Defjne [·] on the syntax and derive the type interpretation [ [·] ] from it s.t. ⊢ M : A implies ⊢ [M] : [ [A] ] Obviously, that's subtle. The correctness of [·] lies in the meta (Darn, Gödel!) The translation must preserve typing (Not easy) In particular, it must preserve conversion (Argh!) Yet, a lot of nice consequences. Does not require non-type-theoretical foundations (monism) Can be implemented in your favourite proof assistant Easy to show (relative) consistency, look at False Easier to understand computationally

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 9 / 27

slide-22
SLIDE 22

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

Syntactic Models

Defjne [·] on the syntax and derive the type interpretation [ [·] ] from it s.t. ⊢ M : A implies ⊢ [M] : [ [A] ] Obviously, that's subtle. The correctness of [·] lies in the meta (Darn, Gödel!) The translation must preserve typing (Not easy) In particular, it must preserve conversion (Argh!) Yet, a lot of nice consequences. Does not require non-type-theoretical foundations (monism) Can be implemented in your favourite proof assistant Easy to show (relative) consistency, look at [ [False] ] Easier to understand computationally

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 9 / 27

slide-23
SLIDE 23

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

(Mis)understanding Dependent Type Theory

There are two essential properties of TT that need to be explicited.

#1. Type theory is call-by-name by construction.

This is because of the unrestricted conversion rule. But the usual monadic interpretation is call-by-value! We need to rely on an alternative decomposition (based on CBPV).

#2. Dependent elimination is hardcore intuitionistic.

It rules out non-standard inductive terms that exist in CBN + efgects Reminiscent of Brouwer vs. Bishop mathematics Needs to be weakened in presence of efgects (« Bishop-style TT »)

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 10 / 27

slide-24
SLIDE 24

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

(Mis)understanding Dependent Type Theory

There are two essential properties of TT that need to be explicited.

#1. Type theory is call-by-name by construction.

This is because of the unrestricted conversion rule. But the usual monadic interpretation is call-by-value! We need to rely on an alternative decomposition (based on CBPV).

#2. Dependent elimination is hardcore intuitionistic.

It rules out non-standard inductive terms that exist in CBN + efgects Reminiscent of Brouwer vs. Bishop mathematics Needs to be weakened in presence of efgects (« Bishop-style TT »)

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 10 / 27

slide-25
SLIDE 25

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

(Mis)understanding Dependent Type Theory

There are two essential properties of TT that need to be explicited.

#1. Type theory is call-by-name by construction.

This is because of the unrestricted conversion rule. But the usual monadic interpretation is call-by-value! We need to rely on an alternative decomposition (based on CBPV).

#2. Dependent elimination is hardcore intuitionistic.

It rules out non-standard inductive terms that exist in CBN + efgects Reminiscent of Brouwer vs. Bishop mathematics Needs to be weakened in presence of efgects (« Bishop-style TT »)

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 10 / 27

slide-26
SLIDE 26

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

My Name is Call, Call-by-Name

TT is intrisically call-by-name because of the conversion rule: Γ ⊢ M : B A ≡β B Γ ⊢ M : A where ≡β is generated by: (λx : A. M) N ≡β M{x := N} To be call-by-value, it would require instead

v generated by:

x A M V

v M x

V where V is a value. But that's not TT...

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 11 / 27

slide-27
SLIDE 27

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

My Name is Call, Call-by-Name

TT is intrisically call-by-name because of the conversion rule: Γ ⊢ M : B A ≡β B Γ ⊢ M : A where ≡β is generated by: (λx : A. M) N ≡β M{x := N} To be call-by-value, it would require instead ≡βv generated by: (λx : A. M) V ≡βv M{x := V} where V is a value. But that's not TT...

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 11 / 27

slide-28
SLIDE 28

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

Tell Me Eleinberg-Moore

Turns out it is easy to give a call-by-name monadic decomposition. Use the Eleinberg-Moore category, i.e. the category of algebras. For us, a T-algebra will be an inhabitant of: A T A A A few remarks: It is hard to formulate the notion of algebra without higher-order types We don't require any equations in (they're quite not algebras) It turns out it is not necessary...

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 12 / 27

slide-29
SLIDE 29

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

Tell Me Eleinberg-Moore

Turns out it is easy to give a call-by-name monadic decomposition. Use the Eleinberg-Moore category, i.e. the category of algebras. For us, a T-algebra will be an inhabitant of: □ □ := ΣA : □. T A → A A few remarks: It is hard to formulate the notion of algebra without higher-order types We don't require any equations in □ □ (they're quite not algebras) It turns out it is not necessary...

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 12 / 27

slide-30
SLIDE 30

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

Required structure

We assume a monad given by universe-polymorphic terms:

T : □i → □i ret : Π(A : □). A → T A bind : Π(A B : □). T A → (A → T B) → T B

and we require no equations!! Furthermore, in Type Theory, types are terms. We want the monad to be self-algebraic. This is given by:

El T

i i

El ret M M

A lot of monads appear to be self-algebraic.

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 13 / 27

slide-31
SLIDE 31

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

Required structure

We assume a monad given by universe-polymorphic terms:

T : □i → □i ret : Π(A : □). A → T A bind : Π(A B : □). T A → (A → T B) → T B

and we require no equations!! Furthermore, in Type Theory, types are terms. We want the monad to be self-algebraic. This is given by:

El : T □ □i → □ □i El (ret □ □ M) ≡β M

A lot of monads appear to be self-algebraic.

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 13 / 27

slide-32
SLIDE 32

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

The Weaning Translation of the Negative Fragment

[x] := x [λx : A. M] := λx : [ [A] ]. [M] [M N] := [M] [N] [□i ] := ret □ □i+1 (T □ □i, µ□) [Πx : A. B] := ret □ □ (Πx : [ [A] ]. [ [B] ], µΠ) [ [A] ] := (El [A]).π1 µ□ : T (T □ □) → □ □ µΠ : T (Πx : [ [A] ]. [ [B] ]) → Πx : [ [A] ]. [ [B] ]

Functional fragment untouched, types mangled into algebras T and x A B x A B Soundness If M A then M A . (In particular, conversion is preserved.)

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 14 / 27

slide-33
SLIDE 33

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

The Weaning Translation of the Negative Fragment

[x] := x [λx : A. M] := λx : [ [A] ]. [M] [M N] := [M] [N] [□i ] := ret □ □i+1 (T □ □i, µ□) [Πx : A. B] := ret □ □ (Πx : [ [A] ]. [ [B] ], µΠ) [ [A] ] := (El [A]).π1 µ□ : T (T □ □) → □ □ µΠ : T (Πx : [ [A] ]. [ [B] ]) → Πx : [ [A] ]. [ [B] ]

Functional fragment untouched, types mangled into algebras [ [□] ] ≡β T □ □ and [ [Πx : A. B] ] ≡β Πx : [ [A] ]. [ [B] ] Soundness If M A then M A . (In particular, conversion is preserved.)

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 14 / 27

slide-34
SLIDE 34

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

The Weaning Translation of the Negative Fragment

[x] := x [λx : A. M] := λx : [ [A] ]. [M] [M N] := [M] [N] [□i ] := ret □ □i+1 (T □ □i, µ□) [Πx : A. B] := ret □ □ (Πx : [ [A] ]. [ [B] ], µΠ) [ [A] ] := (El [A]).π1 µ□ : T (T □ □) → □ □ µΠ : T (Πx : [ [A] ]. [ [B] ]) → Πx : [ [A] ]. [ [B] ]

Functional fragment untouched, types mangled into algebras [ [□] ] ≡β T □ □ and [ [Πx : A. B] ] ≡β Πx : [ [A] ]. [ [B] ] Soundness If Γ ⊢ M : A then [ [Γ] ] ⊢ [M] : [ [A] ]. (In particular, conversion is preserved.)

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 14 / 27

slide-35
SLIDE 35

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

Reduction vs. Efgects

Nothing fancy in the negative fragment, by the well-known duality. 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, consider: b bool M fail non-standard inductive terms In call-by-value + efgects, consider: b unit fail invalid

  • rule

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 15 / 27

slide-36
SLIDE 36

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

Reduction vs. Efgects

Nothing fancy in the negative fragment, by the well-known duality. 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, consider: (λb : bool. M) fail ⇝ non-standard inductive terms In call-by-value + efgects, consider: (λb : unit. fail) ⇝ invalid η-rule

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 15 / 27

slide-37
SLIDE 37

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

Weaning Inductive Types

For the sake of explanation, let's focus on a very simple type: Inductive bool := true | false. We pose:

[bool] := ret □ □ (T bool, µbool) [true] := ret bool true [false] := ret bool false µbool : T (T bool) → T bool

Remark that bool T bool. Soundness If M A then M A .

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 16 / 27

slide-38
SLIDE 38

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

Weaning Inductive Types

For the sake of explanation, let's focus on a very simple type: Inductive bool := true | false. We pose:

[bool] := ret □ □ (T bool, µbool) [true] := ret bool true [false] := ret bool false µbool : T (T bool) → T bool

Remark that [ [bool] ] ≡β T bool. Soundness If Γ ⊢ M : A then [ [Γ] ] ⊢ [M] : [ [A] ].

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 16 / 27

slide-39
SLIDE 39

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

E-LI-MI-NATE!

We need a bit more structure on T to implement elimination:

hbind : Π(A : □)(B : T □ □). T A → (A → [ [B] ]) → [ [B] ] dbind : Π(A : □)(B : A → T □ □). Π(ˆ x : T A). (Π(x : A). [ [B x] ]) → (El (hbind A [□] ˆ x B)).π1

subject to:

hbind A B (ret A M) F ≡β F M dbind A B (ret A M) F ≡β F M

Essentially, hbind and dbind are variants of bind. Remark that the second equation is well-typed ifg the fjrst holds.

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 17 / 27

slide-40
SLIDE 40

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

E-LI-MI-NATE!

We need a bit more structure on T to implement elimination:

hbind : Π(A : □)(B : T □ □). T A → (A → [ [B] ]) → [ [B] ] dbind : Π(A : □)(B : A → T □ □). Π(ˆ x : T A). (Π(x : A). [ [B x] ]) → (El (hbind A [□] ˆ x B)).π1

subject to:

hbind A B (ret A M) F ≡β F M dbind A B (ret A M) F ≡β F M

Essentially, hbind and dbind are variants of bind. Remark that the second equation is well-typed ifg the fjrst holds.

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 17 / 27

slide-41
SLIDE 41

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

Interpreting Non-Dependent Elimination

It is easy to provide a non-dependent eliminator using hbind:

[bool case] : [ [ΠP : □. P → P → bool → P] ] := λ(P : T □ □) (pt pf : [ [P] ]) (ˆ b : T bool). hbind bool P ˆ b (λb. if b then pt else pf)

which has the right reduction rules:

[bool case P pt pf true] ≡β pt [bool case P pt pf false] ≡β pf

Remember:

hbind : Π(A : □)(B : T □ □). T A → (A → [ [B] ]) → [ [B] ] hbind A B (ret A M) F ≡β F M

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 18 / 27

slide-42
SLIDE 42

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

Eliminating Addiction to Dependence

We would like to recover dependent elimination...

... but it's not valid anymore in presence of efgects!

As bool T bool, if T is not the identity then there are closed booleans in the translation which are neither true nor false . Typical of CBN + efgects: recall Herbelin's paradox Already arose in our forcing translation We need to restrict dependent elimination the same way!

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 19 / 27

slide-43
SLIDE 43

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

Eliminating Addiction to Dependence

We would like to recover dependent elimination...

... but it's not valid anymore in presence of efgects!

As [ [bool] ] ≡β T bool, if T is not the identity then there are closed booleans in the translation which are neither [true] nor [false]. Typical of CBN + efgects: recall Herbelin's paradox Already arose in our forcing translation We need to restrict dependent elimination the same way!

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 19 / 27

slide-44
SLIDE 44

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

Eliminating Addiction to Dependence

We would like to recover dependent elimination...

... but it's not valid anymore in presence of efgects!

As [ [bool] ] ≡β T bool, if T is not the identity then there are closed booleans in the translation which are neither [true] nor [false]. Typical of CBN + efgects: recall Herbelin's paradox Already arose in our forcing translation We need to restrict dependent elimination the same way!

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 19 / 27

slide-45
SLIDE 45

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

Eliminating Addiction to Dependence II

The trick consists in sprinkling a few storage operators. For bool:

[θbool ] : [ [bool → (bool → □) → □] ] := [λb. bool case (bool → □) (λk. k true) (λk. k false) b] Only defjned in the source via non-dependent eliminator In particular, agnostic to the actual translation CPS-like to enforce CBV in a CBN world Trivial in CIC: ⊢ Πb : bool. θbool b P = P b

Using dbind, this allows to implement:

bool rect P bool P true P false b bool

bool b P

with the expected reduction rules.

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 20 / 27

slide-46
SLIDE 46

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

Eliminating Addiction to Dependence II

The trick consists in sprinkling a few storage operators. For bool:

[θbool ] : [ [bool → (bool → □) → □] ] := [λb. bool case (bool → □) (λk. k true) (λk. k false) b] Only defjned in the source via non-dependent eliminator In particular, agnostic to the actual translation CPS-like to enforce CBV in a CBN world Trivial in CIC: ⊢ Πb : bool. θbool b P = P b

Using dbind, this allows to implement:

[bool rect] : [ [ΠP : bool → □. P true → P false → Πb : bool. θbool b P] ]

with the expected reduction rules.

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 20 / 27

slide-47
SLIDE 47

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

Weaning Everywhere

There are a lot of monads that satisfy the weaning conditions. Exception monad T A := A + E Non-determinism T A := A × list A Non-termination T A := νX.A + X Writer T A := A × list Ω (the one we need for Hello World) Note that some lead to a logically inconsistent model. A few monads aren't self-algebraic, e.g. state, reader and continuation.

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 21 / 27

slide-48
SLIDE 48

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

Weaning Everywhere

There are a lot of monads that satisfy the weaning conditions. Exception monad T A := A + E Non-determinism T A := A × list A Non-termination T A := νX.A + X Writer T A := A × list Ω (the one we need for Hello World) Note that some lead to a logically inconsistent model. A few monads aren't self-algebraic, e.g. state, reader and continuation.

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 21 / 27

slide-49
SLIDE 49

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

Logic, at Last

In some inconsistent cases, full dependent elimination is valid. Most notably, this is the case for the exception monad.

Let's use that to do a Friedman A-translation on steroids!

Lemmatas With the exception monad T A A E: Full dependent elimination is valid (at the expense of consistency) We have A A E E If A is a fjrst-order type, then A A E. Admissibility of Markov's rule in CIC If A is fjrst-order and

CIC

A then

CIC A.

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 22 / 27

slide-50
SLIDE 50

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

Logic, at Last

In some inconsistent cases, full dependent elimination is valid. Most notably, this is the case for the exception monad.

Let's use that to do a Friedman A-translation on steroids!

Lemmatas With the exception monad T A := A + E: Full dependent elimination is valid (at the expense of consistency) We have [ [¬¬A] ] ∼ = ([ [A] ] → E) → E If A is a fjrst-order type, then [ [A] ] → A + E. Admissibility of Markov's rule in CIC If A is fjrst-order and

CIC

A then

CIC A.

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 22 / 27

slide-51
SLIDE 51

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

Logic, at Last

In some inconsistent cases, full dependent elimination is valid. Most notably, this is the case for the exception monad.

Let's use that to do a Friedman A-translation on steroids!

Lemmatas With the exception monad T A := A + E: Full dependent elimination is valid (at the expense of consistency) We have [ [¬¬A] ] ∼ = ([ [A] ] → E) → E If A is a fjrst-order type, then [ [A] ] → A + E. Admissibility of Markov's rule in CIC If A is fjrst-order and ⊢CIC ¬¬A then ⊢CIC A.

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 22 / 27

slide-52
SLIDE 52

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

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

Back to restricted elimination. It turns out we have a semantic criterion for valid dependent predicates.

LINEARITY.

A concept invented by G. Munch, rephrased recently by P. Levy. Little to do with « linear use of variables » Essentially, f A B linear in CBN if semantically CBV in A. Categorically, f linear ifg it is an algebra morphism. Storage operators turn freely any morphism into a linear one. Can be approximated by a syntactic guard condition. M bool P linear in b if M return b P then N else N P b M

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 23 / 27

slide-53
SLIDE 53

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

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

Back to restricted elimination. It turns out we have a semantic criterion for valid dependent predicates.

LINEARITY.

A concept invented by G. Munch, rephrased recently by P. Levy. Little to do with « linear use of variables » Essentially, f : A → B linear in CBN if semantically CBV in A. Categorically, f linear ifg it is an algebra morphism. Storage operators turn freely any morphism into a linear one. Can be approximated by a syntactic guard condition. Γ ⊢ M : bool . . . P linear in b Γ ⊢ if M return λb. P then N1 else N2 : P{b := M}

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 23 / 27

slide-54
SLIDE 54

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

A Bishop-style Type Theory

We can generalize this restriction to form Baclofen Type Theory. Subset of CIC Independent from the actual translation. Works with forcing Works with weaning Prevents Herbelin's paradox

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

(Take that, Brouwerian HoTT!)

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 24 / 27

slide-55
SLIDE 55

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

A Bishop-style Type Theory

We can generalize this restriction to form Baclofen Type Theory. Subset of CIC Independent from the actual translation. Works with forcing Works with weaning Prevents Herbelin's paradox

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

(Take that, Brouwerian HoTT!)

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 24 / 27

slide-56
SLIDE 56

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

Implementation

A nice paper summarizing this talk.

https://www.pédrot.fr/articles/weaning.pdf

Just as for the forcing translation we have a Coq plugin for weaning.

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

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

(If time permits, small demo here.)

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 25 / 27

slide-57
SLIDE 57

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

Conclusion

A new efgectful translation of TT, the weaning translation

Cosmic version of Eilenberg-Moore categories Gives both programming and logical features

An experimentally confjrmed notion of efgectful type theories, BTT

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

Implementation of a plugin in Coq

Try it out today!

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 26 / 27

slide-58
SLIDE 58

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

Scribitur ad narrandum, non ad probandum

Thanks for your attention.

Pédrot & al. (U. Ljubljana & INRIA) An Efgectful Way 31/01/2017 27 / 27