Monad.Cont
The 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 ... end
The unary monad interface
module type S2 = sig ... end
The 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) -> 'e
include Monad2 with type ('a, 'e) t := ('a, 'e) t
sequence xs
computes a sequence of computations xs
in the left to right order.
module Fn : sig ... end
Various function combinators lifted into the Kleisli category.
module Pair : sig ... end
The pair interface lifted into the monad.
module Triple : sig ... end
The triple interface lifted into a monad.
module Lift : sig ... end
Lifts functions into the monad.
module Exn : sig ... end
Interacting between monads and language exceptions
module Collection : sig ... end
Lifts collection interface into the monad.
module List : Collection.S with type 'a t := 'a list
The Monad.Collection.S2 interface for lists
module Seq : Collection.S with type 'a t := 'a Core_kernel.Sequence.t
The Monad.Collection.S2 interface for sequences
include Syntax.Let.S2 with type ('a, 'e) t := ('a, 'e) t
include Core_kernel.Monad.S2 with type ('a, 'e) t := ('a, 'e) t
module Let_syntax : sig ... end
module Monad_infix : sig ... end
val return : 'a -> ('a, 'b) t
module Let : Syntax.Let.S2 with type ('a, 'e) t := ('a, 'e) t
Monadic 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.t
Make(T)(M)
wraps the monad M
into the continuation monad and fix the type of the whole computation to T.t