Module type Monad.S

Monad signature with let-bindings

This signature provides all the usual monadic operators along with let-bindings definitions used to simplify codes relying on monads. The provided operators are as follows:

The provided let-bindings operators can be used to write simpler and cleaner code. For example, one can write let+ v = compute x in v + 1 instead of map (fun v -> v + 1) (compute x). The more monadic steps, the simpler the code will get when written using those operators. In this module, >>- and let* always correspond to the bind operator while >>-: and let+ always correspond to the map. All those operators are provided in an Operators module to avoid namespace conflicts. Indeed, one can use the expression let open MyMonad.Operators in to use all the let-bindings without risking conflicts by including the other definitions, which have rather common names. This idiom also helps indicate which monad is currently used in a code.

type 'a t
val return : 'a -> 'a t
val flatten : 'a t t -> 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
val bind : ('a -> 'b t) -> 'a t -> 'b t
module Bool : sig ... end

monadic convenience functions around booleans

module Option : sig ... end

applying monadic functions to the option type

module List : sig ... end

applying monadic functions to lists

module Operators : sig ... end