Monad.ContThe continuation monad.
The continuation monad reifies computations by making them available as first class values. A continuation encapsulates an evaluation context of a host language (OCaml in our case). The continuation monad behaves like it is a function monad, except that it provides the call/cc operator. The call/cc operator calls a user provided function with a current continuaton. This continuation can be stored in a state (i.e., if the Continuation monad is composed with the State monad) and later resumed. It may also be used to implement various control structures, i.e., exceptions or coroutines.
The same as with the state monad we provide two interfaces, one with the type of final result of the computation is fixed on the module level, and another where it is a type variable.
module type S = sig ... endThe unary monad interface
module type S2 = sig ... endThe binary monad interface.
include S2
with type ('a, 'r) t = ('a, 'r) cont
and type 'a m = 'a
and type ('a, 'e) e = ('a -> 'e) -> 'einclude Monad2 with type ('a, 'e) t := ('a, 'e) tsequence xs computes a sequence of computations xs in the left to right order.
module Fn : sig ... endVarious function combinators lifted into the Kleisli category.
module Pair : sig ... endThe pair interface lifted into the monad.
module Triple : sig ... endThe triple interface lifted into a monad.
module Lift : sig ... endLifts functions into the monad.
module Exn : sig ... endInteracting between monads and language exceptions
module Collection : sig ... endLifts collection interface into the monad.
module List : Collection.S with type 'a t := 'a listThe Monad.Collection.S2 interface for lists
module Seq : Collection.S with type 'a t := 'a Core_kernel.Sequence.tThe Monad.Collection.S2 interface for sequences
include Syntax.Let.S2 with type ('a, 'e) t := ('a, 'e) tinclude Core_kernel.Monad.S2 with type ('a, 'e) t := ('a, 'e) tmodule Let_syntax : sig ... endmodule Monad_infix : sig ... endval return : 'a -> ('a, 'b) tmodule Let : Syntax.Let.S2 with type ('a, 'e) t := ('a, 'e) tMonadic Binding Operators.
Monadic operators, see Monad.Syntax.S2 for more.
module Make
(T : Core_kernel.T)
(M : Monad) :
S
with type 'a t := 'a T1(T)(M).t
and type 'a m := 'a T1(T)(M).m
and type 'a e := 'a T1(T)(M).e
and type r := T.tMake(T)(M) wraps the monad M into the continuation monad and fix the type of the whole computation to T.t