Control.Comonad
- Package
- purescript-control
- Repository
- purescript/purescript-control
#Comonad Source
class (Extend w) <= Comonad w where
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
Members
extract :: forall a. w a -> a
Re-exports from Control.Extend
#Extend Source
class (Functor w) <= Extend w where
The Extend
class defines the extension operator (<<=)
which extends a local context-dependent computation to
a global computation.
Extend
is the dual of Bind
, and (<<=)
is the dual of
(>>=)
.
Laws:
- Associativity:
extend f <<< extend g = extend (f <<< extend g)
Members
extend :: forall a b. (w a -> b) -> w a -> w b
Instances
#(=<=) Source
Operator alias for Control.Extend.composeCoKleisliFlipped (right-associative / precedence 1)
Re-exports from Data.Functor
#Functor Source
class Functor f where
A Functor
is a type constructor which supports a mapping operation
map
.
map
can be used to turn functions a -> b
into functions
f a -> f b
whose argument and return types use the type constructor f
to represent some computational context.
Instances must satisfy the following laws:
- Identity:
map identity = identity
- Composition:
map (f <<< g) = map f <<< map g
Members
map :: forall b a. (a -> b) -> f a -> f b
Instances
#void Source
void :: forall a f. Functor f => f a -> f Unit
The void
function is used to ignore the type wrapped by a
Functor
, replacing it with Unit
and keeping only the type
information provided by the type constructor itself.
void
is often useful when using do
notation to change the return type
of a monadic computation:
main = forE 1 10 \n -> void do
print n
print (n * n)