class (Apply f) <= Applicative f where
Applicative type class extends the
Apply type class
pure function, which can be used to create values of type
from values of type
Apply provides the ability to lift functions of two or
more arguments to functions whose arguments are wrapped using
Functor provides the ability to lift functions of one
pure can be seen as the function which lifts functions of
zero arguments. That is,
Applicative functors support a lifting
operation for any number of function arguments.
Instances must satisfy the following laws in addition to the
(pure id) <*> v = v
pure (<<<) <*> f <*> g <*> h = f <*> (g <*> h)
(pure f) <*> (pure x) = pure (f x)
u <*> (pure y) = (pure (_ $ y)) <*> u
pure :: forall a. a -> f a
liftA1 :: forall b a f. Applicative f => (a -> b) -> f a -> f b
liftA1 provides a default implementation of
(<$>) for any
Applicative functor, without using
(<$>) as provided
liftA1 can therefore be used to write
instance functorF :: Functor F where map = liftA1
unless :: forall m. Applicative m => Boolean -> m Unit -> m Unit
Perform an applicative action unless a condition is true.
when :: forall m. Applicative m => Boolean -> m Unit -> m Unit
Perform an applicative action when a condition is true.
Re-exports from Control.
class (Functor f) <= Apply f where
Apply class provides the
(<*>) which is used to apply a function
to an argument under a type constructor.
Apply can be used to lift functions of two or more arguments to work on
values wrapped with the type constructor
f. It might also be understood
in terms of the
lift2 :: forall f a b c. Apply f => (a -> b -> c) -> f a -> f b -> f c lift2 f a b = f <$> a <*> b
(<*>) is recovered from
lift2 ($). That is,
the function application operator
($) to arguments wrapped with the
Instances must satisfy the following law in addition to the
- Associative composition:
(<<<) <$> f <*> g <*> h = f <*> (g <*> h)
Apply represents a strong lax semi-monoidal endofunctor.
apply :: forall b a. f (a -> b) -> f a -> f b
Re-exports from Data.
class Functor f where
Functor is a type constructor which supports a mapping operation
map can be used to turn functions
a -> b into functions
f a -> f b whose argument and return types use the type constructor
to represent some computational context.
Instances must satisfy the following laws:
map id = id
map (f <<< g) = map f <<< map g
map :: forall b a. (a -> b) -> f a -> f b
void :: forall a f. Functor f => f a -> f Unit
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)