Unifying graded and parameterised monads Dominic Orchard Philip Wadler Harley Eades III MSFP 2020 ! 3
The humble monad T : ℂ → ℂ 햨햽 T ∘ T μ η return :: a -> m a join :: m m a -> m a T T multiplication unit + associativity and unitality axioms ! 4
Graded monads Functor G : 피 → [ ℂ , ℂ ] (Discrete) monoidal category ( 피 , ∙ , I ) G x ∘ G y 햨햽 μ x , y η G I G ( x ∙ y ) unit multiplication + associativity and unitality axioms [Wadler&Thiemman’03 - Marriage of e ff ects and monads] ! 5 [Katsumata'14 - Parametric e ff ect monads and semantics of e ff ect systems]
Graded monads for type-based effect analysis Γ ⊢ e : MA Γ , x : A ⊢ e ′ � : M B Γ ⊢ e : A monadic metalanguage Γ ⊢ do x ← e ; e ′ � : M B Γ ⊢ return e : M A ! 6
Graded monads for type-based effect analysis graded Γ ⊢ e : G x A Γ , x : A ⊢ e ′ � : G y B Γ ⊢ e : A monadic metalanguage Γ ⊢ do x ← e ; e ′ � : G ( x ∙ y ) B Γ ⊢ return e : G I A ... for refining semantics Humble state 햲헍햺헍햾 A = 햲헍허헋햾 ( ℒ ) → A × 햲헍허헋햾 ( ℒ ) 헀햾헍 : ( l : A ∈ ℒ ) → 햲헍햺헍햾 A 헉헎헍 : ( l : A ∈ ℒ ) → A → 햲헍햺헍햾 1 vs. graded 햲헍햺헍햾 x A = 햲헍허헋햾 ( 헋햾햺햽헌 ( x )) → A × 햲헍허헋햾 ( 헐헋헂헍햾헌 ( x )) 헀햾헍 : ( l : A ∈ ℒ ) → 햲헍햺헍햾 { r ( l )} A 헉헎헍 : ( l : A ∈ ℒ ) → A → 햲헍햺헍햾 { w ( l )} 1 ! 7
Graded monads Functor G : 피 → [ ℂ , ℂ ] (Discrete) monoidal category ( 피 , ∙ , I ) G x ∘ G y 햨햽 μ x , y η G I G ( x ∙ y ) unit multiplication + associativity and unitality axioms ! 8
(unordered) Graded monads Functor G : 피 → [ ℂ , ℂ ] (Discrete) monoidal category ( 피 , ∙ , I ) G x ∘ G y 햨햽 μ x , y η G I G ( x ∙ y ) unordered unit multiplication + associativity and unitality axioms graded monads ! 9
Graded monads Functor G : 피 → [ ℂ , ℂ ] Strict monoidal category ( 피 , ∙ , I , ≤ ) G x ∘ G y G x 햨햽 μ x , y G ( h : x ≤ y ) η G I G y G ( x ∙ y ) unordered unit approximation multiplication + monotonicity + associativity and unitality axioms graded monads ! 10
Parametrised monads P : 핀 허헉 × 핀 → [ ℂ , ℂ ] Functor P ( i , j ) ∘ P ( j , k ) 햨햽 μ i , j , k η i P ( i , i ) P ( i , k ) multiplication unit + associativity and unitality axioms ! 11 [Atkey'06/'09 - Parameterised notions of computation]
Parametrised monads P : 핀 허헉 × 핀 → [ ℂ , ℂ ] Functor P ( i , j ) ∘ P ( j , k ) 햨햽 f P ( i , j ) B g P ( j , k ) C A B μ i , j , k η i A P ( i , k ) C μ i , j , k , C ∘ Pg ∘ f P ( i , i ) P ( i , k ) cf Floyd-Hoare logic multiplication unit { i } C { j } { j } C ′ � { k } + associativity and unitality axioms { i } C ; C ′ � { k } ! 12 [Atkey'06/'09 - Parameterised notions of computation]
Parametrised monads P : 핀 허헉 × 핀 → [ ℂ , ℂ ] Functor P ( i , j ) ∘ P ( j , k ) 햨햽 P ( i , j ) μ i , j , k P ( f : i ′ � → i , g : j → j ′ � ) η i P ( i , i ) P ( i ′ � , j ′ � ) P ( i , k ) multiplication unit approximation + associativity and unitality axioms + dinaturality axioms ! 13 [Atkey'06/'09 - Parameterised notions of computation]
G and P: side-by-side G x ∘ G y P ( i , j ) ∘ P ( j , k ) 햨햽 햨햽 μ i , j , k η i η μ x , y G I P ( i , i ) G ( x ∙ y ) P ( i , k ) Can we unify their definitions? ! 14
Roadmap 2-category-graded monads + generalised unit 2-category- category-graded monads graded monads + generalised unit category-graded discrete monads unordered graded parameterised “oidify” monads monads monads ! 15
“Oidification” 1. concept shown to be equivalent to a single-object category 2. generalise that to a category with more than one object/morphism https://ncatlab.org/nlab/show/horizontal+categorification ! 16
� Monads are lax functors Recall: functor axioms F : ℂ → 픻 (Benabou 1967) id = F id One object Fg ∘ Ff = F ( g ∘ f ) ⋆ One morphism Lax functor axioms id : ⋆ → ⋆ id ⇒ F id Fg ∘ Ff ⇒ F ( g ∘ f ) T : 1 → 햤헇햽허 ( ℂ ) + associativity/unitality is a 2-category 픻 ℂ One object Here natural transformations Morphisms are endofunctors η : id ⇒ T id 2-morphisms are nat. trans. μ : Tid ∘ Tid ⇒ Tid ! 17
Oidifying a monad “Category-graded monad” Monad ℱ 허헉 1 oidification T T / horizontal categorification 햤헇햽허 ( ℂ ) 햤헇햽허 ( ℂ ) (Benabou 1967) Lax functor η x : 햨햽 ⇒ T id x η : 햨햽 ⇒ T id μ f , g : Tf ∘ Tg ⇒ T ( g ∘ f ) μ : T id ∘ T id ⇒ T id ! 18
1. Unordered graded monads are category-graded monads “Category-graded monad” Monoid-graded monad G ℱ 허헉 ( 피 , ∙ , I ) G T [ ℂ , ℂ ] 햤헇햽허 ( ℂ ) η x : 햨햽 ⇒ T id x μ f , g : Tf ∘ Tg ⇒ T ( g ∘ f ) ! 19
Monoids are one-object categories are discrete monoidal categories x ∙ y y x ⋆ I ! 20
1. Unordered graded monads are category-graded monads Category-graded monad Monoid-graded monad G ℱ 허헉 1 ( 피 op , ∙ , I ) ≡ ( 피 , ∙ , I ) G ⊇ T 햤헇햽허 ( ℂ ) ≡ [ ℂ , ℂ ] 햤헇햽허 ( ℂ ) η x : 햨햽 ⇒ T id x η ⋆ : 햨햽 ⇒ G I μ x , y : G x ∘ G y ⇒ G ( x ∙ y ) μ f , g : Tf ∘ Tg ⇒ T ( g ∘ f ) ! 21
2. Graded monads are 2-category-graded monads 2-category-graded monad Category-graded monad T : ℱ 허헉 → 햤헇햽허 ( ℂ ) η x : 햨햽 ⇒ T id x μ f , g : Tf ∘ Tg ⇒ T ( g ∘ f ) + 2-morphism mapping T ( h : g ⇒ f ) : T g ⇒ T f (i.e., � is a 2-category) ℱ � 22
Pomonoids are one object 2-categories are monoidal categories y ⟹ x ≤ y x ⋆ ! 23
2. Graded monads are 2-category-graded monads 2-category-graded monad (Ordered) Graded monad T : ℱ 허헉 → 햤헇햽허 ( ℂ ) G : 1 ( 피 op , ∙ , I , ≤ ) → 햤헇햽허 ( ℂ ) η x : 햨햽 ⇒ T id x η ⋆ : 햨햽 ⇒ G I ⊇ μ x , y : G x ∘ G y ⇒ G ( x ∙ y ) μ f , g : Tf ∘ Tg ⇒ T ( g ∘ f ) G ( h : x ≤ y ) : G x ⇒ G y T ( h : g ⇒ f ) : T g ⇒ T f 2-morphism mapping � 24
Roadmap 2-category- category-graded monads graded monads + generalised unit category-graded discrete monads unordered graded parameterised “oidify” monads monads monads ! 25
3. Discrete parameterised monads are category-graded monads P : 핁 허헉 × 핁 → [ ℂ , ℂ ] where ! has only identity morphisms 핁 Define the category of ! -“dominoes” 핁 (e.g., composition ! ) ( j , k ) ∘ ( i , j ) = ( i , k ) ∇ ( 핁 ) 1 = | 핁 | × | 핁 | Define a category graded monad T : ∇ ( 핁 ) → 햤헇햽허 ( ℂ ) with ! T ( i , j ) = P ( i , j ) = η P η i : 햨햽 ⇒ T ( i , i ) i = μ P μ ( i , j ),( j , k ) : T ( i , j ) ∘ T ( j , k ) ⇒ T ( i , k ) i , j , k ! 26
Parameterised monads have some extra structure P ( i , j ) P ( f : i ′ � → i , g : j → j ′ � ) P ( i ′ � , j ′ � ) morphism mapping (approximation) + dinaturality axioms ! 27
̂ ̂ Generalised units arises from lax natural transformations (Street, 1972) 핊 ⊆ ℱ Wide sub-category η f : X → Y ∈핊 : 햨햽 → Tf Family of morphisms 4. Parameterised monads are category-graded monads + ! η Paper shows details � 28
Roadmap 2-category-graded monads + generalised unit 2-category- category-graded monads graded monads + generalised unit category-graded discrete monads unordered graded parameterised “oidify” monads monads monads ! 29
Example 햢허헇햼햲헍 : ℱ 허헉 → 햤헇햽허 ( ℂ ) | ℱ | = { free , critical } get : 햢허헇햼햲헍 get S put : S → 햢허헇햼햲헍 put 1 lock : free → critical lock : 햢허헇햼햲헍 lock 1 unlock : critical → free get , put : critical → critical unlock : 햢허헇햼햲헍 unlock 1 spawn : ( ∀ f . 햢허헇햼햲헍 ( f : 햿헋햾햾 → 햿헋햾햾 ) 1) → 햢허헇햼햲헍 f 1 � 30
Conclusions Category-graded monad ℱ 허헉 • Shows us where graded & parameterised overlap T • A more general structure that captures both aspects: tracing + restriction 햤헇햽허 ( ℂ ) η x : 햨햽 ⇒ T id x granule-project.github.io μ f , g : Tf ∘ Tg ⇒ T ( g ∘ f ) Thank you! � 31
Recommend
More recommend