package travesty

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

S is the signature of state monads parametrised over their value, but with a fixed state type.

type state

The fixed state type.

include Core_kernel.Monad.S
type 'a t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
val (>>|) : 'a t -> ('a -> 'b) -> 'b t
module Monad_infix : sig ... end
val bind : 'a t -> f:('a -> 'b t) -> 'b t
val map : 'a t -> f:('a -> 'b) -> 'b t
val join : 'a t t -> 'a t
val ignore_m : 'a t -> unit t
val all : 'a t list -> 'a list t
val all_unit : unit t list -> unit t
val all_ignore : unit t list -> unit t
  • deprecated [since 2018-02] Use [all_unit]
module Let_syntax : sig ... end
include T_monad.Extensions with type 'a t := 'a t
val when_m : Base.bool -> f:(Base.unit -> Base.unit t) -> Base.unit t

when_m predicate ~f returns f () when predicate is true, and return () otherwise.

val unless_m : Base.bool -> f:(Base.unit -> Base.unit t) -> Base.unit t

unless_m predicate ~f returns f () when predicate is false, and return () otherwise.

include Generic with type ('a, 's) t := 'a t and type 's state := state and type 'a final := 'a

State monads share the signatures of their builder functions with state transformers...

include State_transform_intf.Generic_builders with type ('a, 's) t := 'a t with type 's state := state with type 'a final := 'a
include State_transform_intf.Generic_types with type ('a, 's) t := 'a t with type 's state := state with type 'a final := 'a
val make : (state -> state * 'a) -> 'a t

make creates a context-sensitive computation that can modify both the current context and the data passing through.

Specialised builders

val peek : (state -> 'a) -> 'a t

peek creates a context-sensitive computation that can look at the current context, but not modify it.

val modify : (state -> state) -> Base.unit t

modify creates a context-sensitive computation that can look at and modify the current context.

val return : 'a -> 'a t

return lifts a value or monad into a stateful computation.

...as well as their runner functions...

include State_transform_intf.Generic_runners with type ('a, 's) t := 'a t and type 'a final := 'a and type 's state := state
include State_transform_intf.Generic_types with type ('a, 's) t := 'a t with type 'a final := 'a with type 's state := state
val run' : 'a t -> state -> state * 'a

run' unfolds a t into a function from context to final state and result.

val run : 'a t -> state -> 'a

run unfolds a t into a function from context to final result. To get the final context, use run' or call peek at the end of the computation.

...and fixed-point combinators.

include State_transform_intf.Fix with type ('a, 's) t := 'a t
val fix : f:(('a -> 'a t) -> 'a -> 'a t) -> 'a -> 'a t

fix ~f init builds a fixed point on f.

At each step, f is passed a continuation mu and a value a. It may choose to return a recursive application of mu, or some value derived from a.

To begin with, f is applied to mu and init.

OCaml

Innovation. Community. Security.