Module Kxclib.MonadOps

Parameters

module M : Monadic

Signature

include Monadic with type 'x t := 'x M.t
val return : 'x -> 'x M.t
val bind : 'x M.t -> ('x -> 'y M.t) -> 'y M.t
val (>>=) : 'a M.t -> ('a -> 'b M.t) -> 'b M.t

monadic binding

val (>>) : 'x M.t -> 'y M.t -> 'y M.t

monadic sequencing

NB if expr1 and expr2 both incur side effects, expr1 >> expr2 will usually incur side effects of expr2 first and then expr1, which is usually not what the programmer expects

val (>|=) : 'x M.t -> ('x -> 'y) -> 'y M.t

monadic mapping

val returning : 'a -> 'b -> 'a M.t

monadic version of constant

val mlift : ('a -> 'b) -> 'a -> 'b M.t
val mwrap : ('a -> 'b) -> 'a M.t -> 'b M.t
val do_cond : bool -> ('a -> 'b M.t) -> ('a -> 'b M.t) -> 'a -> 'b M.t

m >>= do_cond cond f_true f_false performs f_true or f_false on value enclosed in m, respectively when cond is true or false;

functionally equiv. to fun c f1 f2 -> if c then f1 else f2 but return type of f1 and f2 is restricted to _ t

val do_if : bool -> ('a -> unit M.t) -> 'a -> unit M.t

m >>= do_if cond f is equiv. to m >>= do_cond cond f (returning ())

val sequence_list : 'a M.t list -> 'a list M.t
val (>>=*) : 'x M.t list -> ('x list -> 'y M.t) -> 'y M.t

monadic binding version of sequence_list