Preface_specs.Applicative
An Applicative
is a functor with lifting and sequencing capabilities. Applicative
is more general (and by extension weaker) than a Monad
. An Applicative
is also a Functor
.
To have a predictable behaviour, the instance of Applicative
must obey some laws.
apply = lift2 id
lift2 f x y = f <$> x <*> y
pure id <*> v = v
pure (%) <*> u <*> v <*> w = u <*> (v <*> w)
pure f <*> pure x = pure (f x)
u <*> pure y = pure ((|>) y) <*> u
u *> v = (id <$ u) <*> v
u <* v = lift2 const u v
fmap f x = pure f <*> x
lift2 p (lift2 q u v) = lift2 f u % lift2 g v
module type WITH_PURE = sig ... end
Minimal interface using map
and product
.
module type WITH_PURE_MAP_AND_PRODUCT = sig ... end
Minimal interface using map
and product
.
module type WITH_PURE_AND_APPLY = sig ... end
Minimal interface using apply
.
module type WITH_PURE_AND_LIFT2 = sig ... end
Minimal interface using lift2
.
module type CORE = sig ... end
Basis operations.
module type OPERATION = sig ... end
Additional operations.
module type SYNTAX = sig ... end
Syntax extensions.
module type INFIX = sig ... end
Infix operators.
module type API = sig ... end
The complete interface of an Applicative
.