Description
This module describes a structure intermediate between a functor and a monad (technically, a strong lax monoidal functor). Compared with monads, this interface lacks the full power of the binding operation >>=
, but
Traversable
class.This interface was introduced for parsers by Niklas Röjemo, because it admits more sharing than the monadic interface. The names here are mostly based on parsing work by Doaitse Swierstra.
For more details, see Applicative Programming with Effects, by Conor McBride and Ross Paterson, online at http://www.soi.city.ac.uk/~ross/papers/Applicative.html.
Applicative functorsclass Functor f => Applicative f whereSource
A functor with application, providing operations to
A minimal complete definition must include implementations of these functions satisfying the following laws:
pure
id
<*>
v = v
pure
(.) <*>
u <*>
v <*>
w = u <*>
(v <*>
w)
pure
f <*>
pure
x = pure
(f x)
u <*>
pure
y = pure
($
y) <*>
u
The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:
u*>
v =pure
(const
id
)<*>
u<*>
v u<*
v =pure
const
<*>
u<*>
v
As a consequence of these laws, the Functor
instance for f
will satisfy
fmap
f x =pure
f<*>
x
If f
is also a Monad
, it should satisfy
and pure
= return
(
(which implies that <*>
) = ap
pure
and <*>
satisfy the applicative functor laws).
Methods
Lift a value.
(<*>) :: f (a -> b) -> f a -> f bSource
Sequential application.
(*>) :: f a -> f b -> f bSource
Sequence actions, discarding the value of the first argument.
(<*) :: f a -> f b -> f aSource
Sequence actions, discarding the value of the second argument.
Alternatives Instances Utility functions(<$) :: Functor f => a -> f b -> f aSource
Replace all locations in the input with the same value. The default definition is
, but this may be overridden with a more efficient version.fmap
. const
liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f dSource
Lift a ternary function to actions.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4