-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathComonad.purs
More file actions
25 lines (21 loc) · 788 Bytes
/
Comonad.purs
File metadata and controls
25 lines (21 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Control.Comonad
( class Comonad, extract
, module Control.Extend
, module Data.Functor
) where
import Control.Extend (class Extend, duplicate, extend, (<<=), (=<=), (=>=), (=>>))
import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>))
import Data.Monoid (class Monoid, mempty)
-- | `Comonad` extends the `Extend` class with the `extract` function
-- | which extracts a value, discarding the comonadic context.
-- |
-- | `Comonad` is the dual of `Monad`, and `extract` is the dual of `pure`.
-- |
-- | Laws:
-- |
-- | - Left Identity: `extract <<= xs = xs`
-- | - Right Identity: `extract (f <<= xs) = f xs`
class Extend w <= Comonad w where
extract :: forall a. w a -> a
instance comonadFn :: Monoid m => Comonad ((->) m) where
extract f = f mempty