interaction laws of monads and comonads
play

Interaction laws of monads and comonads Tarmo Uustalu joint work - PowerPoint PPT Presentation

Interaction laws of monads and comonads Tarmo Uustalu joint work with Shin-ya Katsumata and Exequiel Rivas OWLS seminar, 29 July 2020 Effects happen in interaction To run, an effectful program behaving as a computation needs to interact with


  1. Interaction laws of monads and comonads Tarmo Uustalu joint work with Shin-ya Katsumata and Exequiel Rivas OWLS seminar, 29 July 2020

  2. Effects happen in interaction To run, an effectful program behaving as a computation needs to interact with a environment that an effect-providing machine behaves as E.g., a nondeterministic program needs a machine making choices; a stateful program needs a machine coherently responding to fetch and store commands.

  3. This talk We propose and study functor-functor interaction laws, monad-comonad interaction laws. as mathematical concepts for describing interaction protocols in this scenario. Functor-functor interaction laws are for unrestricted notions of computation Monad-comonad interaction laws are for notions of computation that are closed under “doing nothing” (just returning), sequential composition.

  4. Outline Functor-functor and monad-comonad interaction laws Some examples and degeneracy theorems Dual—greatest interacting functor or monad; Sweedler dual—greatest interacting comonad Some examples Residual interaction laws (to counteract degeneracies, but not only) Object-object and monoid-comonoid interaction laws in duoidal categories

  5. Functor-functor interaction laws Let C be a Cartesian category (symmetric monoidal will work too). Think C = Set . A functor-functor interaction law is given by two functors F , G : C → C and a family of maps φ X , Y : FX × GY → X × Y natural in X , Y . Legend: X – values, FX – computations Y – states, GY – environments (incl an initial state)

  6. Examples of functor-functor interaction laws ( O ′ × F X = O × (( I ⇒ X ) × X )), ���� ���� ���� ���� outp inp outp ext ch G Y = O ⇒ (( I × Y ) + ( O ′ ⇒ Y )) ���� ���� ���� ���� inp inp outp int ch for some sets O , I , O ′ φ (( o , ( f , ( o ′ , x ))) , g ) = � inl ( i , y ) �→ ( f i , y ) case g o of inr h ( x , h o ′ ) �→ We can vary φ , e.g., change o ′ to o ∗ o ′ in the 2nd case for some ∗ : O × O ′ → O ′ We can also vary G , e.g., take G ′ Y = N ⇒ ( I × Y ) φ ′ ( o , ( f , )) , g ) = let ( i , y ) = g 42 in ( f i , y ) (This is like session types, no?)

  7. � � � � Monad-comonad interaction laws A monad-comonad interaction law is given by a monad ( T , η, µ ) and a comonad ( D , ε, δ ) and a family of maps ψ X , Y : TX × DY → X × Y natural in X , Y such that ψ TX , DY � TX × DY ψ X , Y � X × Y X × Y X × Y TTX × DDY id × ε Y id × δ Y X × DY TTX × DY ψ X , Y � X × Y ψ X , Y η X × id µ X × id � X × Y TX × DY TX × DY Legend: X – values, TX – computations Y – states, DY – environments (incl an initial state)

  8. Some examples of mnd-cmnd int laws TX = S ⇒ X (the reader monad), DY = S 0 × Y for some S 0 , S and c : S 0 → S ψ ( f , ( s 0 , y )) = ( f ( c s 0 ) , y ) Legend: X – values, S – “views” of store, Y – (control) states, S 0 – states of store TX = S ⇒ ( S × X ) (the state monad), DY = S 0 × ( S 0 ⇒ Y ) for some S 0 , S , c : S 0 → S and d : S 0 × S → S 0 forming a (very well-behaved) lens ψ ( f , ( s 0 , g )) = let ( s ′ , x ) = f ( c s 0 ) in ( x , g ( d ( s 0 , s ′ ))) TX = µ Z . X + Z × Z , DY = ν W . Y × ( W + W )

  9. � Monad-comonad interaction laws are monoids A functor-functor interaction law map between ( F , G , φ ), ( F ′ , G ′ , φ ′ ) is given by nat. transfs. f : F → F ′ , g : G ′ → G such that φ X , Y � X × Y FX × GY id × g Y FX × G ′ Y φ ′ f X × id � X , Y � X × Y F ′ X × G ′ Y Functor-functor interaction laws form a category with a composition-based monoidal structure. These categories are isomorphic: monad-comonad interaction laws; monoid objects of the category of functor-functor interaction laws.

  10. � � Some degeneracy thms for func-func int laws Assume C is extensive (“has well-behaved coproducts”). If F has a nullary operation, i.e., a family of maps c x : 1 → FX natural in X (eg, F = Maybe) or a binary commutative operation, i.e., a family of maps c x : X × X → FX natural in X such that X × X c x � FX sym c x X × X (eg, F = M + fin ) and F interacts with G , then GY ∼ = 0.

  11. � � � � A degeneracy thm for mnd-cmnd int laws If T has a binary associative operation, ie a family of maps c x : X × X → TX natural in X such that ( X × X ) × X ℓ X � TX ass rX X × ( X × X ) where cX × η X � TX × TX cTX � TTX µ X � TX ℓ X = ( X × X ) × X η X × cX � TX × TX cTX � TTX µ X � TX r X = X × ( X × X ) (eg, T = List + ), then any int law ψ of T and D obeys ℓ X × id � TX × DY ( X × X ) × X × DY ψ X , Y fst × id × id � ψ X , Y � X × Y cX × id � TX × DY X × X × DY id × snd × id � rX × id � TX × DY ψ X , Y X × ( X × X ) × DY

  12. Dual of a functor Assume now C is Cartesian closed. For a functor G : C → C , its dual is the functor G ◦ : C → C is � G ◦ X = Y GY ⇒ ( X × Y ) (if this end exists). ( − ) ◦ is a functor [ C , C ] op → [ C , C ] (if all functors C → C are dualizable; if not, restrict to some full subcategory of [ C , C ] closed under dualization).

  13. � � � � � Dual of a functor ctd The dual G ◦ is the “greatest” functor interacting with G . These categories are isomorphic: functor-functor interaction laws; pairs of functors F , G with nat. transfs. F → G ◦ ; pairs of functors F , G with nat. transfs. G → F ◦ . FX × GY → X × Y � FX → Y GY ⇒ ( X × Y ) � �� � G ◦ X FX × GY X × Y F G ◦ G ◦ X × GY G ◦

  14. Some examples of dual Let GY = 1. Then G ◦ X ∼ = 0. Let GY = Σ a : A . G ′ aY , then G ◦ X ∼ = Π a : A . ( G ′ a ) ◦ X . In particular, for GY = 0, we have G ◦ X ∼ = 1 and, for GY = G 0 Y + G 1 Y , we have G ◦ X ∼ = G ◦ 0 X × G ◦ 1 X . Let GY = A ⇒ Y . We have G ◦ X ∼ = A × X . But: Let GY = Π a : A . G ′ a Y . We only have Σ a : A . ( G ′ a ) ◦ X → G ◦ X . Id ◦ ∼ = Id. But we only have G ◦ 0 · G ◦ 1 → ( G 0 · G 1 ) ◦ . For any G with a nullary or a binary commutative operation, we have G ◦ X ∼ = 0.

  15. Dual of a comonad / Sweedler dual a monad The dual D ◦ of a comonad D is a monad. This is because ( − ) ◦ : [ C , C ] op → [ C , C ] is lax monoidal, so send monoids to monoids. But ( − ) ◦ is not oplax monoidal, does not send comonoids to comonoids. So the dual T ◦ of a monad T is generally not a comonad. However we can talk about the Sweedler dual T • of T . Informally, it is defined as the greatest functor D that is smaller than the functor T ◦ and carries a comonad structure η • , µ • agreeing with η ◦ , µ ◦ .

  16. � � � � � � � � � � � � � � � Dual of a comonad / Sweedler dual of a monad ctd Formally, the Sweedler dual of the monad T is the comonad ( T • , η • , µ • ) together with a natural transformation ι : T • → T ◦ such that m T , T � ( T · T ) ◦ e � Id ◦ ι · ι � T ◦ · T ◦ T • · T • Id η • � µ • � e − 1 ?? η ◦ µ ◦ ι � T ◦ ι � T ◦ T • T • and such that, for any comonad ( D , ε, δ ) together with a natural transformation ψ satisfying the same conditions, there is a unique comonad map h : D → T • satisfying m T , T � ( T · T ) ◦ e ι · ι � Id ◦ � T ◦ · T ◦ T • · T • Id h · h � ψ · ψ η • η ◦ Id µ • µ ◦ D · D ι ι � T ◦ � T ◦ ε T • T • δ h h ψ ψ D D

  17. Some examples of dual and Sweedler dual Let TX = List + X ∼ = Σ n : N . ([0 .. n ] ⇒ X ) (the nonempty list monad) . We have T ◦ Y ∼ = Π n : N . ([0 .. n ] × Y ) but T • Y ∼ = Y × ( Y + Y ). Let TX = S ⇒ ( S × X ) ∼ = ( S ⇒ S ) × ( S ⇒ X ) (the state monad). We have T ◦ Y = ( S ⇒ S ) ⇒ ( S × Y ) but T • Y = S × ( S ⇒ Y ).

  18. Residual interaction laws Given a monad ( R , η R , µ R ) on C . Eg, R = Maybe, M + or M . A residual functor-functor interaction law is given by two functors F , G : C → C and a family of maps φ X , Y : FX × GY → R ( X × Y ) natural in X , Y .

  19. � � � � � Residual interaction laws ctd A residual monad-comonad interaction law is given by a monad ( T , η, µ ), a comonad ( D , ε, δ ) and a family of maps ψ X , Y : TX × DY → R ( X × Y ) natural in X , Y such that ψ TX , DY R ψ X , Y � R ( TX × DY ) � RR ( X × Y ) X × Y X × Y TTX × DDY id × ε Y � id × δ Y η R X × Y µ R X × Y X × DY TTX × DY η X × id ψ X , Y ψ X , Y µ X × id � R ( X × Y ) � R ( X × Y ) TX × DY TX × DY R -residual functor-functor interaction laws form a monoidal category with R -residual monad-comonad interaction laws as monoids.

  20. Interaction laws and Chu spaces The Day convolution of F , G is � X , Y C ( X × Y , Z ) • ( FX × GY ) ( F ⋆ G ) Z = (if this coend exists). These categories are isomorphic: functor-functor interaction laws; Chu spaces on ([ C , C ] , Id , ⋆ ) with vertex Id, ie, triples of two functors F , G with a nat transf F ⋆ G → Id. (if ⋆ is defined for all functors). FX × GY → X × Y C ( X × Y , Z ) → C ( FX × GY , Z ) � X , Y C ( X × Y , Z ) • ( FX × GY ) → Z � �� � ( F ⋆ G ) Z

Recommend


More recommend