Move functor definition to Kleisli.Monad

This commit is contained in:
Frederik Hanghøj Iversen 2018-02-28 19:00:21 +01:00
parent 70221377d3
commit 3c77c69cf6

View file

@ -117,7 +117,8 @@ module Kleisli {a b : Level} ( : Category a b) where
private
= a b
open Category using (Arrow ; 𝟙 ; Object ; _∘_ ; _>>>_)
module = Category
open using (Arrow ; 𝟙 ; Object ; _∘_ ; _>>>_)
-- | Data for a monad.
--
@ -188,6 +189,29 @@ module Kleisli {a b : Level} ( : Category a b) where
lem : fmap g fmap f bind (fmap g (pure f))
lem = isDistributive (pure g) (pure f)
-- | This formulation gives rise to the following endo-functor.
private
rawR : RawFunctor
RawFunctor.func* rawR = RR
RawFunctor.func→ rawR f = bind (pure f)
isFunctorR : IsFunctor rawR
IsFunctor.isIdentity isFunctorR = begin
bind (pure 𝟙) ≡⟨ cong bind (proj₁ .isIdentity)
bind pure ≡⟨ isIdentity
𝟙
IsFunctor.isDistributive isFunctorR {f = f} {g} = begin
bind (pure (g f)) ≡⟨⟩
fmap (g f) ≡⟨ fusion
fmap g fmap f ≡⟨⟩
bind (pure g) bind (pure f)
-- TODO: Naming!
R : Functor
Functor.raw R = rawR
Functor.isFunctor R = isFunctorR
record Monad : Set where
field
raw : RawMonad
@ -251,26 +275,6 @@ module _ {a b : Level} { : Category a b} where
open K.Monad m
open NaturalTransformation
rawR : RawFunctor
RawFunctor.func* rawR = RR
RawFunctor.func→ rawR f = bind (pure f)
isFunctorR : IsFunctor rawR
IsFunctor.isIdentity isFunctorR = begin
bind (pure 𝟙) ≡⟨ cong bind (proj₁ .isIdentity)
bind pure ≡⟨ isIdentity
𝟙
IsFunctor.isDistributive isFunctorR {f = f} {g} = begin
bind (pure (g f)) ≡⟨⟩
fmap (g f) ≡⟨ fusion
fmap g fmap f ≡⟨⟩
bind (pure g) bind (pure f)
R : Functor
Functor.raw R = rawR
Functor.isFunctor R = isFunctorR
: Functor
= F[ R R ]