This commit is contained in:
Frederik Hanghøj Iversen 2018-03-06 10:16:42 +01:00
parent 0cebe1e866
commit 485703c85e

View file

@ -7,6 +7,7 @@ open import Data.Product
open import Cubical open import Cubical
open import Cubical.NType.Properties using (lemPropF ; lemSig) open import Cubical.NType.Properties using (lemPropF ; lemSig)
open import Cubical.GradLemma using (gradLemma)
open import Cat.Category open import Cat.Category
open import Cat.Category.Functor as F open import Cat.Category.Functor as F
@ -357,6 +358,7 @@ module Kleisli {a b : Level} ( : Category a b) where
isMonad : IsMonad raw isMonad : IsMonad raw
open IsMonad isMonad public open IsMonad isMonad public
private
module _ (raw : RawMonad) where module _ (raw : RawMonad) where
open RawMonad raw open RawMonad raw
propIsIdentity : isProp IsIdentity propIsIdentity : isProp IsIdentity
@ -376,6 +378,7 @@ module Kleisli {a b : Level} ( : Category a b) where
= propIsNatural raw (isNatural x) (isNatural y) i = propIsNatural raw (isNatural x) (isNatural y) i
IsMonad.isDistributive (propIsMonad raw x y i) IsMonad.isDistributive (propIsMonad raw x y i)
= propIsDistributive raw (isDistributive x) (isDistributive y) i = propIsDistributive raw (isDistributive x) (isDistributive y) i
module _ {m n : Monad} (eq : Monad.raw m Monad.raw n) where module _ {m n : Monad} (eq : Monad.raw m Monad.raw n) where
private private
eqIsMonad : (λ i IsMonad (eq i)) [ Monad.isMonad m Monad.isMonad n ] eqIsMonad : (λ i IsMonad (eq i)) [ Monad.isMonad m Monad.isMonad n ]
@ -417,28 +420,25 @@ module _ {a b : Level} { : Category a b} where
Kleisli.Monad.isMonad (forth m) = forthIsMonad (M.Monad.isMonad m) Kleisli.Monad.isMonad (forth m) = forthIsMonad (M.Monad.isMonad m)
module _ (m : K.Monad) where module _ (m : K.Monad) where
private
open K.Monad m open K.Monad m
module MR = M.RawMonad
module MI = M.IsMonad
backRaw : M.RawMonad backRaw : M.RawMonad
MR.R backRaw = R M.RawMonad.R backRaw = R
MR.pureNT backRaw = pureNT M.RawMonad.pureNT backRaw = pureNT
MR.joinNT backRaw = joinNT M.RawMonad.joinNT backRaw = joinNT
private private
open MR backRaw open M.RawMonad backRaw
module R = Functor (MR.R backRaw) module R = Functor (M.RawMonad.R backRaw)
backIsMonad : M.IsMonad backRaw backIsMonad : M.IsMonad backRaw
MI.isAssociative backIsMonad {X} = begin M.IsMonad.isAssociative backIsMonad {X} = begin
joinT X R.func→ (joinT X) ≡⟨⟩ joinT X R.func→ (joinT X) ≡⟨⟩
join fmap (joinT X) ≡⟨⟩ join fmap (joinT X) ≡⟨⟩
join fmap join ≡⟨ isNaturalForeign join fmap join ≡⟨ isNaturalForeign
join join ≡⟨⟩ join join ≡⟨⟩
joinT X joinT (R.func* X) joinT X joinT (R.func* X)
MI.isInverse backIsMonad {X} = inv-l , inv-r M.IsMonad.isInverse backIsMonad {X} = inv-l , inv-r
where where
inv-l = begin inv-l = begin
joinT X pureT (R.func* X) ≡⟨⟩ joinT X pureT (R.func* X) ≡⟨⟩
@ -453,23 +453,21 @@ module _ {a b : Level} { : Category a b} where
Monoidal.Monad.raw (back m) = backRaw m Monoidal.Monad.raw (back m) = backRaw m
Monoidal.Monad.isMonad (back m) = backIsMonad m Monoidal.Monad.isMonad (back m) = backIsMonad m
-- I believe all the proofs here should be `refl`.
module _ (m : K.Monad) where module _ (m : K.Monad) where
open K.Monad m open K.Monad m
-- open K.RawMonad (K.Monad.raw m)
bindEq : {X Y} bindEq : {X Y}
K.RawMonad.bind (forthRaw (backRaw m)) {X} {Y} K.RawMonad.bind (forthRaw (backRaw m)) {X} {Y}
K.RawMonad.bind (K.Monad.raw m) K.RawMonad.bind (K.Monad.raw m)
bindEq {X} {Y} = begin bindEq {X} {Y} = begin
K.RawMonad.bind (forthRaw (backRaw m)) ≡⟨⟩ K.RawMonad.bind (forthRaw (backRaw m)) ≡⟨⟩
(λ f joinT Y func→ R f) ≡⟨⟩
(λ f join fmap f) ≡⟨⟩ (λ f join fmap f) ≡⟨⟩
(λ f bind (f >>> pure) >>> bind 𝟙) ≡⟨ funExt lem (λ f bind (f >>> pure) >>> bind 𝟙) ≡⟨ funExt lem
(λ f bind f) ≡⟨⟩ (λ f bind f) ≡⟨⟩
bind bind
where where
joinT = proj₁ joinNT lem : (f : Arrow X (omap Y))
lem : (f : Arrow X (omap Y)) bind (f >>> pure) >>> bind 𝟙 bind f bind (f >>> pure) >>> bind 𝟙
bind f
lem f = begin lem f = begin
bind (f >>> pure) >>> bind 𝟙 bind (f >>> pure) >>> bind 𝟙
≡⟨ isDistributive _ _ ≡⟨ isDistributive _ _
@ -481,13 +479,9 @@ module _ {a b : Level} { : Category a b} where
≡⟨ cong bind (proj₂ .isIdentity) ≡⟨ cong bind (proj₂ .isIdentity)
bind f bind f
_&_ : {a b} {A : Set a} {B : Set b} A (A B) B
x & f = f x
forthRawEq : forthRaw (backRaw m) K.Monad.raw m forthRawEq : forthRaw (backRaw m) K.Monad.raw m
K.RawMonad.omap (forthRawEq _) = omap K.RawMonad.omap (forthRawEq _) = omap
K.RawMonad.pure (forthRawEq _) = pure K.RawMonad.pure (forthRawEq _) = pure
-- stuck
K.RawMonad.bind (forthRawEq i) = bindEq i K.RawMonad.bind (forthRawEq i) = bindEq i
fortheq : (m : K.Monad) forth (back m) m fortheq : (m : K.Monad) forth (back m) m
@ -550,7 +544,6 @@ module _ {a b : Level} { : Category a b} where
backeq : (m : M.Monad) back (forth m) m backeq : (m : M.Monad) back (forth m) m
backeq m = M.Monad≡ (backRawEq m) backeq m = M.Monad≡ (backRawEq m)
open import Cubical.GradLemma
eqv : isEquiv M.Monad K.Monad forth eqv : isEquiv M.Monad K.Monad forth
eqv = gradLemma forth back fortheq backeq eqv = gradLemma forth back fortheq backeq