SLIDE 1 Pierre Cagne
for Kan Extension Seminar II
Université Paris Diderot
When computational monads go clubbing
Category Theory 2017 – Vancouver
SLIDE 2
- 1. Crash course in computational monads
- 2. Clubs
- 3. Strong monads
- 4. Computational monads as clubs
SLIDE 3
1 Crash course in computational monads
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 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 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 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 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 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 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 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 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 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
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
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
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
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
2 Clubs
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 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 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 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 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 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
S(g) n1
Warning
Highly non symmetric!
Remark
Reminiscent of the operadic substitution product.
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
S(g) n1
Warning
Highly non symmetric!
Remark
Reminiscent of the operadic substitution product.
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
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
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
3 Strong monads
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,
good enough to be effects.
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,
good enough to be effects.
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
4 Computational monads as clubs
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
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
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
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 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 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 Thank you!
http://www.normalesup.org/~cagne/ https://pierrecagne.github.io