2018-02-24 14:13:25 +00:00
|
|
|
|
{-# OPTIONS --cubical --allow-unsolved-metas #-}
|
2018-02-23 16:33:09 +00:00
|
|
|
|
module Cat.Category.Monad where
|
|
|
|
|
|
2018-02-24 11:52:16 +00:00
|
|
|
|
open import Agda.Primitive
|
|
|
|
|
|
|
|
|
|
open import Data.Product
|
|
|
|
|
|
2018-02-23 16:33:09 +00:00
|
|
|
|
open import Cubical
|
|
|
|
|
|
|
|
|
|
open import Cat.Category
|
2018-02-24 11:52:16 +00:00
|
|
|
|
open import Cat.Category.Functor as F
|
|
|
|
|
open import Cat.Category.NaturalTransformation
|
2018-02-23 16:33:09 +00:00
|
|
|
|
open import Cat.Categories.Fun
|
2018-02-24 11:52:16 +00:00
|
|
|
|
|
2018-02-24 14:13:25 +00:00
|
|
|
|
-- "A monad in the monoidal form" [voe]
|
2018-02-24 11:52:16 +00:00
|
|
|
|
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
|
|
|
|
|
|
2018-02-24 14:13:25 +00:00
|
|
|
|
η : Transformation F.identity R
|
|
|
|
|
η = proj₁ ηNat
|
|
|
|
|
μ : Transformation F[ R ∘ R ] R
|
|
|
|
|
μ = proj₁ μNat
|
2018-02-24 13:00:52 +00:00
|
|
|
|
|
2018-02-24 11:52:16 +00:00
|
|
|
|
private
|
2018-02-24 13:00:52 +00:00
|
|
|
|
module R = Functor R
|
|
|
|
|
module RR = Functor F[ R ∘ R ]
|
2018-02-24 11:52:16 +00:00
|
|
|
|
module _ {X : Object} where
|
|
|
|
|
-- module IdRX = Functor (F.identity {C = RX})
|
|
|
|
|
η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}
|
|
|
|
|
|
|
|
|
|
μ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
|
2018-02-24 13:00:52 +00:00
|
|
|
|
|
2018-02-24 13:01:57 +00:00
|
|
|
|
record Monad : Set ℓ where
|
|
|
|
|
field
|
|
|
|
|
raw : RawMonad
|
|
|
|
|
isMonad : IsMonad raw
|
|
|
|
|
open IsMonad isMonad public
|
|
|
|
|
|
2018-02-24 14:13:25 +00:00
|
|
|
|
-- "A monad in the Kleisli form" [voe]
|
2018-02-24 13:00:52 +00:00
|
|
|
|
module Kleisli {ℓa ℓb : Level} (ℂ : Category ℓa ℓb) where
|
|
|
|
|
private
|
|
|
|
|
ℓ = ℓa ⊔ ℓb
|
|
|
|
|
|
|
|
|
|
open Category ℂ hiding (IsIdentity)
|
|
|
|
|
record RawMonad : Set ℓ where
|
|
|
|
|
field
|
|
|
|
|
RR : Object → Object
|
2018-02-24 14:13:25 +00:00
|
|
|
|
-- Note name-change from [voe]
|
|
|
|
|
ζ : {X : Object} → ℂ [ X , RR X ]
|
2018-02-24 13:00:52 +00:00
|
|
|
|
rr : {X Y : Object} → ℂ [ X , RR Y ] → ℂ [ RR X , RR Y ]
|
2018-02-24 14:25:07 +00:00
|
|
|
|
-- Note the correspondance with Haskell:
|
|
|
|
|
--
|
|
|
|
|
-- RR ~ m
|
|
|
|
|
-- ζ ~ pure
|
|
|
|
|
-- rr ~ flip (>>=)
|
|
|
|
|
--
|
|
|
|
|
-- Where those things have these types:
|
|
|
|
|
--
|
|
|
|
|
-- m : 𝓤 → 𝓤
|
|
|
|
|
-- pure : x → m x
|
|
|
|
|
-- flip (>>=) :: (a → m b) → m a → m b
|
|
|
|
|
--
|
2018-02-24 13:00:52 +00:00
|
|
|
|
IsIdentity = {X : Object}
|
2018-02-24 14:13:25 +00:00
|
|
|
|
→ rr ζ ≡ 𝟙 {RR X}
|
2018-02-24 13:00:52 +00:00
|
|
|
|
IsNatural = {X Y : Object} (f : ℂ [ X , RR Y ])
|
2018-02-24 14:13:25 +00:00
|
|
|
|
→ (ℂ [ rr f ∘ ζ ]) ≡ f
|
2018-02-24 13:00:52 +00:00
|
|
|
|
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
|
2018-02-24 14:13:25 +00:00
|
|
|
|
|
|
|
|
|
-- Problem 2.3
|
|
|
|
|
module _ {ℓa ℓb : Level} {ℂ : Category ℓa ℓb} where
|
|
|
|
|
private
|
|
|
|
|
open Category ℂ using (Object ; Arrow ; 𝟙)
|
|
|
|
|
open Functor using (func* ; func→)
|
|
|
|
|
module M = Monoidal ℂ
|
|
|
|
|
module K = Kleisli ℂ
|
|
|
|
|
|
|
|
|
|
module _ (m : M.RawMonad) where
|
|
|
|
|
private
|
|
|
|
|
open M.RawMonad m
|
|
|
|
|
module Kraw = K.RawMonad
|
|
|
|
|
|
|
|
|
|
RR : Object → Object
|
|
|
|
|
RR = func* R
|
|
|
|
|
|
|
|
|
|
R→ : {A B : Object} → ℂ [ A , B ] → ℂ [ RR A , RR B ]
|
|
|
|
|
R→ = func→ R
|
|
|
|
|
|
|
|
|
|
ζ : {X : Object} → ℂ [ X , RR X ]
|
|
|
|
|
ζ = {!!}
|
|
|
|
|
|
|
|
|
|
rr : {X Y : Object} → ℂ [ X , RR Y ] → ℂ [ RR X , RR Y ]
|
|
|
|
|
-- Order is different now!
|
|
|
|
|
rr {X} {Y} f = ℂ [ f ∘ {!!} ]
|
|
|
|
|
where
|
|
|
|
|
μY : ℂ [ func* F[ R ∘ R ] Y , func* R Y ]
|
|
|
|
|
μY = μ Y
|
|
|
|
|
ζY : ℂ [ Y , RR Y ]
|
|
|
|
|
ζY = ζ {Y}
|
|
|
|
|
|
|
|
|
|
forthRaw : K.RawMonad
|
|
|
|
|
Kraw.RR forthRaw = RR
|
|
|
|
|
Kraw.ζ forthRaw = ζ
|
|
|
|
|
Kraw.rr forthRaw = rr
|
|
|
|
|
|
|
|
|
|
module _ {raw : M.RawMonad} (m : M.IsMonad raw) where
|
|
|
|
|
open M.IsMonad m
|
|
|
|
|
module Kraw = K.RawMonad (forthRaw raw)
|
|
|
|
|
module Kis = K.IsMonad
|
|
|
|
|
isIdentity : Kraw.IsIdentity
|
|
|
|
|
isIdentity = {!!}
|
|
|
|
|
|
|
|
|
|
isNatural : Kraw.IsNatural
|
|
|
|
|
isNatural = {!!}
|
|
|
|
|
|
|
|
|
|
isDistributive : Kraw.IsDistributive
|
|
|
|
|
isDistributive = {!!}
|
|
|
|
|
|
|
|
|
|
forthIsMonad : K.IsMonad (forthRaw raw)
|
|
|
|
|
Kis.isIdentity forthIsMonad = isIdentity
|
|
|
|
|
Kis.isNatural forthIsMonad = isNatural
|
|
|
|
|
Kis.isDistributive forthIsMonad = isDistributive
|
|
|
|
|
|
|
|
|
|
forth : M.Monad → K.Monad
|
|
|
|
|
Kleisli.Monad.raw (forth m) = forthRaw (M.Monad.raw m)
|
|
|
|
|
Kleisli.Monad.isMonad (forth m) = forthIsMonad (M.Monad.isMonad m)
|
|
|
|
|
|
|
|
|
|
eqv : isEquiv M.Monad K.Monad forth
|
|
|
|
|
eqv = {!!}
|
|
|
|
|
|
|
|
|
|
Monoidal≃Kleisli : M.Monad ≃ K.Monad
|
|
|
|
|
Monoidal≃Kleisli = forth , eqv
|