Legend:
Library
Module
Module type
Parameter
Class
Class type
Monad is an interface, that is pervasives through many data types. Such types are called monadic. Monad interface is practical for both data (list, option, etc), and codata (Future, Lwt, Deferred, Lazy, Continuation). The interpretation of each monad interface is different for each data type. But in general monad interface consists of two functions:
return : 'a -> 'a t
bind : 'a t -> ('a -> 'b t) -> 'b t.
This is a minimal definition. Many functions can be inferred based on this interface, see Monad.S for the full list.
Option monad, as well as Or_error and Result monads, is suitable for building control flow. They can be seen as a reification of exception. A chain of such monads link with the bind function, will break as soon as monadic zero value occurs.
Future, as well as Lwt or Async, provides a safe access to codata, i.e., to a value that is defined somewhere outside of the main program, or to a value that is represented by an effectful computation, not by inductive data. Lwt and Async are also so called IO monads, that reifies side-effects, mostly IO. State monad is another example of reification of computation effect. The State monad is useful to build purely functional computation with side-effects. The side-effect, e.g., writing to a memory cell, is reified into an OCaml value, and practically becomes a first class value, i.e., it can be stored, printed, etc.