package mnd

  1. Overview
  2. Docs

Parameters

module M : MONOID

Signature

include MONAD with type 'a t = 'a * M.t
include MONAD_DEF with type 'a t = 'a * M.t
type 'a t = 'a * M.t
val return : 'a -> 'a t

return x should be a monad which produces x

val map : ('a1 -> 'a2) -> 'a1 t -> 'a2 t

Run a monad and apply a function to the result

val bind : 'a1 t -> ('a1 -> 'a2 t) -> 'a2 t

Sequential composition: First run one monad, then another based on the first result

val let+ : 'a1 t -> ('a1 -> 'a2) -> 'a2 t

This is just syntactic sugar for map: let+ x = m in f x is the same as map f m.

val let* : 'a1 t -> ('a1 -> 'a2 t) -> 'a2 t

This is just syntactic sugar for bind: let* x = m in f x is the same as bind m f.

val (>>=) : 'a1 t -> ('a1 -> 'a2 t) -> 'a2 t

Operator version of bind, i.e. m1 >>= m2 is the same as bind m1 m2

val (>>) : 'a1 t -> 'a2 t -> 'a2 t

Like (>>=) but ignores the result of the first monad, i.e. m1 >> m2 is the same as m1 >>= fun _ -> m2

val (|>>) : 'a t -> ('a -> 'b) -> 'b t

This is the operator version of map, i.e. m |>> f is the same as map f m

val foldM : ('a2 -> 'a1 -> 'a2 t) -> 'a2 -> 'a1 list -> 'a2 t

Monadic version of List.fold_left: the folding function computes the new accumulator value inside the monad.

val fold1M : ('a -> 'a -> 'a t) -> 'a list -> 'a t

Same as foldM but the first element of the list is taken as the initial accumulator value. Throws an Invalid_argument exception on the empty list.

val mapM : ('a -> 'b t) -> 'a list -> 'b list t

Monadic version of List.map: the new elements are computed inside the monad.

val forM : 'a list -> ('a -> 'b t) -> 'b list t

This is just mapM with its arguments flipped.

val iterM : ('a -> unit t) -> 'a list -> unit t

Monadic version of List.iter

val ifM : bool -> (unit -> unit t) -> unit t

Conditionally run the given monad or just return ()

val write : M.t -> unit * M.t
OCaml

Innovation. Community. Security.