When computational monads go clubbing Category Theory 2017 - - PowerPoint PPT Presentation

when computational monads go clubbing
SMART_READER_LITE
LIVE PREVIEW

When computational monads go clubbing Category Theory 2017 - - PowerPoint PPT Presentation

Pierre Cagne for Kan Extension Seminar II Universit Paris Diderot When computational monads go clubbing Category Theory 2017 Vancouver 1. Crash course in computational monads 2. Clubs 3. Strong monads 4. Computational monads as clubs


slide-1
SLIDE 1

Pierre Cagne

for Kan Extension Seminar II

Université Paris Diderot

When computational monads go clubbing

Category Theory 2017 – Vancouver

slide-2
SLIDE 2
  • 1. Crash course in computational monads
  • 2. Clubs
  • 3. Strong monads
  • 4. Computational monads as clubs
slide-3
SLIDE 3

1 Crash course in computational monads

slide-4
SLIDE 4

Program

def f(): x = input(”Enter a number:”) return 2*int(x) def g(y): return y*y a = g(f()) b = g(f())

Modelization

f : 1 → N g : N → N

slide-5
SLIDE 5

Program

def f(): x = input(”Enter a number:”) return 2*int(x) def g(y): return y*y a = g(f()) b = g(f())

Modelization

f : 1 → N g : N → N Hence f is just a constant integer n ∈ N, and we should get a = b = g(n)...

slide-6
SLIDE 6

Program

def f(): x = input(”Enter a number:”) return 2*int(x) def g(y): return y*y a = g(f()) b = g(f())

Modelization

f : 1 → NN g : N → N Now f is not constant anymore.

slide-7
SLIDE 7

Program

def f(): x = input(”Enter a number:”) return 2*int(x) def g(y): return y*y a = g(f()) b = g(f())

Modelization

f : 1 → NN g : N → N Now f is not constant anymore. But how to compose g with f now?

slide-8
SLIDE 8

Program

def f(): x = input(”Enter a number:”) return 2*int(x) def g(y): return y*y a = g(f()) b = g(f())

Modelization

f : 1 → NN g : N → N Now f is not constant anymore. But how to compose g with f now? Use Kleisli composition of the monad (−)N : Set → Set

slide-9
SLIDE 9

Program

def f(a,b): if b == 0: raise Error else: return a/b def g(y): return y*y a = g(f(4,0)) b = g(f(4,2))

Modelization

f : N2 → N g : N → N

slide-10
SLIDE 10

Program

def f(a,b): if b == 0: raise Error else: return a/b def g(y): return y*y a = g(f(4,0)) b = g(f(4,2))

Modelization

f : N2 → N g : N → N Hence a as well as b should have a defined value in N...

slide-11
SLIDE 11

Program

def f(a,b): if b == 0: raise Error else: return a/b def g(y): return y*y a = g(f(4,0)) b = g(f(4,2))

Modelization

f : N2 → N + e g : N → N e is a singleton Now f is only partially defined.

slide-12
SLIDE 12

Program

def f(a,b): if b == 0: raise Error else: return a/b def g(y): return y*y a = g(f(4,0)) b = g(f(4,2))

Modelization

f : N2 → N + e g : N → N e is a singleton Now f is only partially defined. But how to compose g with f now?

slide-13
SLIDE 13

Program

def f(a,b): if b == 0: raise Error else: return a/b def g(y): return y*y a = g(f(4,0)) b = g(f(4,2))

Modelization

f : N2 → N + e g : N → N e is a singleton Now f is only partially defined. But how to compose g with f now? Use Kleisli composition of the monad − + e : Set → Set

slide-14
SLIDE 14

Big picture (Moggi)

Side effects of a programming language can be encoded by a monad T. Distinguish values (objects A) from computations (images TA). Programs are interpreted by morphisms A TB. Composition of programs occurs in the Kleisli category of T. (One wants good properties for T: strong, pullbacks preserving, etc.)

slide-15
SLIDE 15

Big picture (Moggi)

Side effects of a programming language can be encoded by a monad T. Distinguish values (objects A) from computations (images TA). Programs are interpreted by morphisms A TB. Composition of programs occurs in the Kleisli category of T. (One wants good properties for T: strong, pullbacks preserving, etc.)

slide-16
SLIDE 16

Big picture (Moggi)

Side effects of a programming language can be encoded by a monad T. Distinguish values (objects A) from computations (images TA). Programs are interpreted by morphisms A → TB. Composition of programs occurs in the Kleisli category of T. (One wants good properties for T: strong, pullbacks preserving, etc.)

slide-17
SLIDE 17

Big picture (Moggi)

Side effects of a programming language can be encoded by a monad T. Distinguish values (objects A) from computations (images TA). Programs are interpreted by morphisms A → TB. Composition of programs occurs in the Kleisli category of T. (One wants good properties for T: strong, pullbacks preserving, etc.)

slide-18
SLIDE 18

2 Clubs

slide-19
SLIDE 19

Clubs

T S is cartesian when each TX SX TX SY is a pullback square.

M : cartesian natural transformations in [A, A].

Definition (Clubs)

A monad S j n on is a club whenever S is monoidal for: T S T S TT SS

n S

Remark: in particular, cartesian monads are clubs.

Idea

When has a terminal , exploits the equivalence S S. Clubs over S are now easily spotted as monoids in S .

slide-20
SLIDE 20

Clubs

α : T → S is cartesian when each TX SX TX SY is a pullback square.

M : cartesian natural transformations in [A, A].

Definition (Clubs)

A monad S j n on is a club whenever S is monoidal for: T S T S TT SS

n S

Remark: in particular, cartesian monads are clubs.

Idea

When has a terminal , exploits the equivalence S S. Clubs over S are now easily spotted as monoids in S .

slide-21
SLIDE 21

Clubs

T S is cartesian when each TX SX TX SY is a pullback square.

M : cartesian natural transformations in [A, A].

Definition (Clubs)

A monad (S, j, n) on A is a club whenever M/S is monoidal for: (T

α

→ S) ⊗ (T′

β

→ S) = TT′ αβ → SS

n

→ S Remark: in particular, cartesian monads are clubs.

Idea

When has a terminal , exploits the equivalence S S. Clubs over S are now easily spotted as monoids in S .

slide-22
SLIDE 22

Clubs

T S is cartesian when each TX SX TX SY is a pullback square.

M : cartesian natural transformations in [A, A].

Definition (Clubs)

A monad (S, j, n) on A is a club whenever M/S is monoidal for: (T

α

→ S) ⊗ (T′

β

→ S) = TT′ αβ → SS

n

→ S Remark: in particular, cartesian monads are clubs.

Idea

When has a terminal , exploits the equivalence S S. Clubs over S are now easily spotted as monoids in S .

slide-23
SLIDE 23

Clubs

T S is cartesian when each TX SX TX SY is a pullback square.

M : cartesian natural transformations in [A, A].

Definition (Clubs)

A monad (S, j, n) on A is a club whenever M/S is monoidal for: (T

α

→ S) ⊗ (T′

β

→ S) = TT′ αβ → SS

n

→ S Remark: in particular, cartesian monads are clubs.

Idea

When A has a terminal 1, exploits the equivalence A/S1 ≃ M/S. Clubs over S are now easily spotted as monoids in A/S1.

slide-24
SLIDE 24

Tensoring in A/S1

For K

f

→ S1 and X

g

→ S1, the tensor f ⊗ g is obtained as: K ×S1 SX K SX S1 SS1 S1

  • f

S(g) n1

Warning

Highly non symmetric!

Remark

Reminiscent of the operadic substitution product.

slide-25
SLIDE 25

Tensoring in A/S1

For K

f

→ S1 and X

g

→ S1, the tensor f ⊗ g is obtained as: K ×S1 SX K SX S1 SS1 S1

  • f

S(g) n1

Warning

Highly non symmetric!

Remark

Reminiscent of the operadic substitution product.

slide-26
SLIDE 26

Enriched clubs

V : “nice” cartesian closed category

Definition

A

  • monad S j n on a
  • category

is a enriched club whenever S j n is an ordinary one on .

Key feature

There is still a one-to-one correspondance between clubs over S and monoids in S .

slide-27
SLIDE 27

Enriched clubs

V : “nice” cartesian closed category

Definition

A V-monad (S, j, n) on a V-category A is a enriched club whenever (S0, j, n) is an ordinary one on A0.

Key feature

There is still a one-to-one correspondance between clubs over S and monoids in S .

slide-28
SLIDE 28

Enriched clubs

V : “nice” cartesian closed category

Definition

A V-monad (S, j, n) on a V-category A is a enriched club whenever (S0, j, n) is an ordinary one on A0.

Key feature

There is still a one-to-one correspondance between clubs over S and monoids in A0/S01.

slide-29
SLIDE 29

3 Strong monads

slide-30
SLIDE 30

Every category is canonically enriched

Fact

Every small category A with products is enriched over V = Psh(A), by defining A (A, B) : C → A (A × C, B) A

  • monad is then an ordinary monad T

j n on together with a natural map

A C

SA C S A C that makes T a strong monad.

Conclusion

Cartesian strong monads are enriched clubs. Conversely,

  • clubs are

good enough to be effects.

slide-31
SLIDE 31

Every category is canonically enriched

Fact

Every small category A with products is enriched over V = Psh(A), by defining A (A, B) : C → A (A × C, B) A V-monad is then an ordinary monad (T0, j, n) on A together with a natural map σA,C : SA × C → S(A × C) that makes T0 a strong monad.

Conclusion

Cartesian strong monads are enriched clubs. Conversely,

  • clubs are

good enough to be effects.

slide-32
SLIDE 32

Every category is canonically enriched

Fact

Every small category A with products is enriched over V = Psh(A), by defining A (A, B) : C → A (A × C, B) A V-monad is then an ordinary monad (T0, j, n) on A together with a natural map σA,C : SA × C → S(A × C) that makes T0 a strong monad.

Conclusion

Cartesian strong monads are enriched clubs. Conversely, V-clubs are good enough to be effects.

slide-33
SLIDE 33

4 Computational monads as clubs

slide-34
SLIDE 34

Clubs over Error

Take A = Set for the following. The monad S e Set Set is strong and cartesian. Hence it is an enriched club, and clubs over S are easily spotted as monoids in Set e. Those are M Ke e where M is a plain monoid, which induces the club T X M X Ke

slide-35
SLIDE 35

Clubs over Error

Take A = Set for the following. The monad S = − + e : Set → Set is strong and cartesian. Hence it is an enriched club, and clubs over S are easily spotted as monoids in Set e. Those are M Ke e where M is a plain monoid, which induces the club T X M X Ke

slide-36
SLIDE 36

Clubs over Error

Take A = Set for the following. The monad S = − + e : Set → Set is strong and cartesian. Hence it is an enriched club, and clubs over S are easily spotted as monoids in Set/1 + e. Those are M Ke e where M is a plain monoid, which induces the club T X M X Ke

slide-37
SLIDE 37

Clubs over Error

Take A = Set for the following. The monad S = − + e : Set → Set is strong and cartesian. Hence it is an enriched club, and clubs over S are easily spotted as monoids in Set/1 + e. Those are M + Ke → 1 + e where M is a plain monoid, which induces the club T : X → (M × X) + Ke

slide-38
SLIDE 38

What is this effect?

Program

MAX = 2147483647 def f(a,b): print ”Computing a quotient ...” print ”Div by 0 raise an error.” if b == 0: raise DivisionByZero else: return a/b def g(y): print ”Squaring ...” print ”Too big numbers raise errors.” if y > MAX: raise TooBigError else: return y*y a = g(f(4,0)) b = g(f(2**32 ,2)) c = g(f(4,2))

Modelization

A program is modelled as a map A → TB Composing programs is Kleisli- composing functions: for f : A → TB and g : B → TC, define g ◦ f (x) as f (x) if f (x) ∈ Ke g(y) if f (x) = (m, y) and g(y) ∈ Ke (mm′, z) if f (x) = (m, y) and g(y) = (m′, z)

Here : T = (M × −) + Ke with M monoid.

slide-39
SLIDE 39

What is this effect?

Program

MAX = 2147483647 def f(a,b): print ”Computing a quotient ...” print ”Div by 0 raise an error.” if b == 0: raise DivisionByZero else: return a/b def g(y): print ”Squaring ...” print ”Too big numbers raise errors.” if y > MAX: raise TooBigError else: return y*y a = g(f(4,0)) b = g(f(2**32 ,2)) c = g(f(4,2))

Modelization

A program is modelled as a map A → TB Composing programs is Kleisli- composing functions: for f : A → TB and g : B → TC, define g ◦ f (x) as f (x) if f (x) ∈ Ke g(y) if f (x) = (m, y) and g(y) ∈ Ke (mm′, z) if f (x) = (m, y) and g(y) = (m′, z)

Here : T = (M×−)+Ke with M the free monoid on the ASCII alphabet and Ke = {e1, e2}.

slide-40
SLIDE 40

Thank you!

http://www.normalesup.org/~cagne/ https://pierrecagne.github.io