Preface_specs.Selective
A Selective
(applicative functor) allows to declare effects statically and select which execute dynamically. It is an algebraic structure between Applicative
and Monad
. A Selective
is also an Applicative
.
To have a predictable behaviour, the instance of Selective
must obey some laws.
x <*? pure id = Either.case id id <$> x
pure x <*? (y *> z) = (pure x <*? y) *> (pure x <*? z)
x <*? (y <*? z) = (f <$> x) <*? (g <$> y) <*? (h <$> z)
f <$> select x y) = (select (Bifunctor.map_snd f <$> x) (((%) f) <$> y)
(select (Bifunctor.map_fst f <$> x) y) = (select x ((%>) f) <$> y))
(select x (f <$> y)) = (select (Bifunctor.map_fst (flip f) <$> x) ((|>) \
<$> y))
(x <*? pure y) = (Either.case y id <$> x)
(pure (Right x) <*? y) = pure x
(pure (Left x) <*? y) = ((|>) x) <$> y
A selective
is Rigid
if apply
can be defined in term of select
f <*> g = apply f g
(x *> (y <*? z)) = ((x *> y) <*? z)
module type WITH_SELECT = sig ... end
Minimal definition using select
without Applicative
requirements.
module type WITH_BRANCH = sig ... end
Minimal definition using branch
without Applicative
requirements.
module type WITH_PURE_AND_SELECT = sig ... end
Standard requirement including pure
and select
.
module type WITH_PURE_AND_BRANCH = sig ... end
Standard requirement including pure
and branch
.
module type CORE = sig ... end
Basis operation.
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 a Selective
.