cat/src/Cat/Category/Monad.agda

111 lines
3.3 KiB
Agda
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{-# OPTIONS --cubical #-}
module Cat.Category.Monad where
open import Agda.Primitive
open import Data.Product
open import Cubical
open import Cat.Category
open import Cat.Category.Functor as F
open import Cat.Category.NaturalTransformation
open import Cat.Categories.Fun
-- "A monad in the monoidal form" [vlad]
module Monoidal {a b : Level} ( : Category a b) where
private
= a b
open Category hiding (IsAssociative)
open NaturalTransformation
record RawMonad : Set where
field
R : Functor
-- pure
ηNat : NaturalTransformation F.identity R
-- (>=>)
μNat : NaturalTransformation F[ R R ] R
private
module R = Functor R
module RR = Functor F[ R R ]
module _ {X : Object} where
-- module IdRX = Functor (F.identity {C = RX})
η : Transformation F.identity R
η = proj₁ ηNat
ηX : [ X , R.func* X ]
ηX = η X
RηX : [ R.func* X , R.func* (R.func* X) ] -- [ R.func* X , {!R.func* (R.func* X))!} ]
RηX = R.func→ ηX
ηRX = η (R.func* X)
IdRX : Arrow (R.func* X) (R.func* X)
IdRX = 𝟙 {R.func* X}
μ : Transformation F[ R R ] R
μ = proj₁ μNat
μX : [ RR.func* X , R.func* X ]
μX = μ X
RμX : [ R.func* (RR.func* X) , RR.func* X ]
RμX = R.func→ μX
μRX : [ RR.func* (R.func* X) , R.func* (R.func* X) ]
μRX = μ (R.func* X)
IsAssociative' : Set _
IsAssociative' = [ μX RμX ] [ μX μRX ]
IsInverse' : Set _
IsInverse'
= [ μX ηRX ] IdRX
× [ μX RηX ] IdRX
-- We don't want the objects to be indexes of the type, but rather just
-- universally quantify over *all* objects of the category.
IsAssociative = {X : Object} IsAssociative' {X}
IsInverse = {X : Object} IsInverse' {X}
record IsMonad (raw : RawMonad) : Set where
open RawMonad raw public
field
isAssociative : IsAssociative
isInverse : IsInverse
record Monad : Set where
field
raw : RawMonad
isMonad : IsMonad raw
open IsMonad isMonad public
-- "A monad in the Kleisli form" [vlad]
module Kleisli {a b : Level} ( : Category a b) where
private
= a b
open Category hiding (IsIdentity)
record RawMonad : Set where
field
RR : Object Object
η : {X : Object} [ X , RR X ]
rr : {X Y : Object} [ X , RR Y ] [ RR X , RR Y ]
-- Name suggestions are welcome!
IsIdentity = {X : Object}
rr η 𝟙 {RR X}
IsNatural = {X Y : Object} (f : [ X , RR Y ])
( [ rr f η ]) f
IsDistributive = {X Y Z : Object} (g : [ Y , RR Z ]) (f : [ X , RR Y ])
[ rr g rr f ] rr ( [ rr g f ])
record IsMonad (raw : RawMonad) : Set where
open RawMonad raw public
field
isIdentity : IsIdentity
isNatural : IsNatural
isDistributive : IsDistributive
record Monad : Set where
field
raw : RawMonad
isMonad : IsMonad raw
open IsMonad isMonad public