Skip to content

Commit e992eef

Browse files
author
Marcin Szamotulski
committed
Coyoneda - monad, comonad docs
1 parent 061d760 commit e992eef

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Data/Coyoneda.purs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ instance bindCoyoneda :: Bind f => Bind (Coyoneda f) where
6767
liftCoyoneda $
6868
runExists (\(CoyonedaF k fi) -> lowerCoyoneda <<< f <<< k =<< fi) e
6969

70+
-- | When `f` is a Monad then it is a functor as well. In this case
71+
-- | `liftCoyoneda` is not only a functor isomorphism but also a monad
72+
-- | isomorphism, i.e. the following law holds
73+
-- | ```purescript
74+
-- | liftCoyoneda fa >>= liftCoyoneda <<< g = liftCoyoneda $ fa >>= g
75+
-- | ```
7076
instance monadCoyoneda :: Monad f => Monad (Coyoneda f)
7177

7278
instance monadTransCoyoneda :: MonadTrans Coyoneda where
@@ -76,6 +82,12 @@ instance extendCoyoneda :: Extend w => Extend (Coyoneda w) where
7682
extend f (Coyoneda e) =
7783
runExists (\(CoyonedaF k fi) -> liftCoyoneda $ f <<< coyoneda k <<= fi) e
7884

85+
-- | As in the monad case: if `w` is a comonad, then it is a functor, thus
86+
-- | `liftCoyoneda` is an iso of functors, but moreover it is an iso of
87+
-- | comonads, i.e. the following law holds:
88+
-- | ```purescript
89+
-- | g <<= liftCoyoneda w = liftCoyoneda $ g <<< liftCoyoneda <<= w
90+
-- | ```
7991
instance comonadCoyoneda :: Comonad w => Comonad (Coyoneda w) where
8092
extract (Coyoneda e) = runExists (\(CoyonedaF k fi) -> k $ extract fi) e
8193

0 commit comments

Comments
 (0)