Module type Writer.API

The complete interface of a Writer monad which introduces the Monad API into the Writer API.

type tape

The encapsulated tape.

type 'a monad

The inner monad.

type 'a t = ('a * tape) monad

The type held by the writer monad.

val upper : 'a monad -> 'a t

promote monad into the transformation.

val writer : ('a * tape) -> 'a t

Construct a writer computation from a (result, output) pair.

val run : 'a t -> ('a * tape) monad

Unwrap the writer computation.

val exec : 'a t -> tape monad

Extract the output from the writer computation.

val tell : tape -> unit t

tell helps to enrich the output. This is done thanks to the semigroup combine operation.

val listen : 'a t -> ('a * tape) t

listen executes the effect and return both the result and the corresponding output within the effect.

val listens : (tape -> 'b) -> 'a t -> ('a * 'b) t

Performs the action and adds the result of applying the function to the output to the value of the computation.

val pass : ('a * (tape -> tape)) t -> 'a t

pass executes the effect and apply the function to the corresponding output.

val censor : (tape -> tape) -> 'a t -> 'a t

censor executes the effects, apply the function to the corresponding output and returns an effects with the value unchanged.

Monad

module Monad : Monad.API

Type

Type

Functions

include Indexed_monad.WITH_RETURN with type ('a, 'index) t := 'a t
include Indexed_bind.WITH_BIND with type ('a, 'index) t := 'a t
val bind : ('a -> 'b t) -> 'a t -> 'b t

bind f m passes the result of computation m to function f.

include Indexed_monad.WITH_RETURN with type ('a, 'index) t := 'a t
include Indexed_bind.WITH_MAP_AND_JOIN with type ('a, 'index) t := 'a t
val map : ('a -> 'b) -> 'a t -> 'b t

Mapping over from 'a to 'b.

val join : 'a t t -> 'a t

join remove one level of monadic structure, projecting its bound argument into the outer level.

include Indexed_monad.WITH_RETURN with type ('a, 'index) t := 'a t
val return : 'a -> 'a t

Lift a value into a t.

include Indexed_bind.WITH_KLEISLI_COMPOSITION with type ('a, 'index) t := 'a t
val compose_left_to_right : ('a -> 'b t) -> ('b -> 'c t) -> 'a -> 'c t

Composing monadic functions using Kleisli Arrow (from left to right).

val compose_right_to_left : ('b -> 'c t) -> ('a -> 'b t) -> 'a -> 'c t

Composing monadic functions using Kleisli Arrow (from right to left).

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

Mapping over t from 'a to 'b.

val lift2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t

Lift a binary function that acts on arbitrary values into a function that acts t values.

val lift3 : ('a -> 'b -> 'c -> 'd) -> 'a t -> 'b t -> 'c t -> 'd t

Lift a ternary function that acts on arbitrary values into a function that acts t values.

val replace : 'a -> 'b t -> 'a t

Create a new t, replacing all values of the given functor by given a value of 'a.

val void : 'a t -> unit t

Create a new t, replacing all values in the given functor by unit.

Infix operators

module Infix : Indexed_monad.INFIX with type ('a, 'index) t := 'a t
val (=|<) : ('a -> 'b) -> 'a t -> 'b t

Infix version of CORE.map.

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

Infix flipped version of CORE.map.

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

Infix flipped version of CORE.bind.

val (=<<) : ('a -> 'b t) -> 'a t -> 'b t

Infix version of CORE.bind.

val (>=>) : ('a -> 'b t) -> ('b -> 'c t) -> 'a -> 'c t

Infix version of CORE.compose_left_to_right.

val (<=<) : ('b -> 'c t) -> ('a -> 'b t) -> 'a -> 'c t

Infix version of OPERATION.compose_right_to_left.

val (>>) : unit t -> 'b t -> 'b t

Sequentially compose two actions, discarding any value produced by the first.

val (<<) : 'a t -> unit t -> 'a t

Sequentially compose two actions, discarding any value produced by the second.

val (<$>) : ('a -> 'b) -> 'a t -> 'b t

Infix version of CORE.map.

val (<&>) : 'a t -> ('a -> 'b) -> 'b t

Flipped and infix version of CORE.map.

val (<$) : 'a -> 'b t -> 'a t

Infix version of OPERATION.replace.

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

Flipped and infix version of OPERATION.replace.

Syntax

module Syntax : Indexed_monad.SYNTAX with type ('a, 'index) t := 'a t
val let* : 'a t -> ('a -> 'b t) -> 'b t

Syntactic shortcuts for flipped version of CORE.bind:

let* x = e in f is equals to bind (fun x -> f) e.

val let+ : 'a t -> ('a -> 'b) -> 'b t

let operator for mapping.