package preface

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

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.

Laws

To have a predictable behaviour, the instance of Selective must obey some laws.

  1. x <*? pure id = Either.case id id <$> x
  2. pure x <*? (y *> z) = (pure x <*? y) *> (pure x <*? z)
  3. x <*? (y <*? z) = (f <$> x) <*? (g <$> y) <*? (h <$> z)
  4. f <$> select x y) = (select (Bifunctor.map_snd f <$> x) (((%) f) <$> y)
  5. (select (Bifunctor.map_fst f <$> x) y) = (select x ((%>) f) <$> y))
  6. (select x (f <$> y)) = (select (Bifunctor.map_fst (flip f) <$> x) ((|>) \ <$> y))
  7. (x <*? pure y) = (Either.case y id <$> x)
  8. (pure (Right x) <*? y) = pure x
  9. (pure (Left x) <*? y) = ((|>) x) <$> y

Laws for Rigid Selectives

A selective is Rigid if apply can be defined in term of select

  1. f <*> g = apply f g
  2. (x *> (y <*? z)) = ((x *> y) <*? z)

Minimal definition

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.

Structure anatomy

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.

Complete API

module type API = sig ... end

The complete interface of a Selective.

Additional references

OCaml

Innovation. Community. Security.