package travesty
Module State.To_SSource
To_S flattens a S2 into an S by fixing the state type to B.t.
Parameters
Signature
The fixed state type.
include Core_kernel.Monad.S with type 'a t = ('a, B.t) M.t
module Monad_infix : sig ... endmodule Let_syntax : sig ... endinclude T_monad.Extensions with type 'a t := 'a t
when_m predicate ~f returns f () when predicate is true, and return () otherwise.
unless_m predicate ~f returns f () when predicate is false, and return () otherwise.
tee_m val ~f executes f val for its monadic action, then returns val.
Example:
let fail_if_negative x =
T_on_error.when_m (Int.is_negative x)
~f:(fun () -> Or_error.error_string "value is negative!")
in
Or_error.(
42 |> T_on_error.tee_m ~f:fail_if_negative >>| (fun x -> x * x)
) (* Ok (1764) *)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
make creates a context-sensitive computation that can modify both the current context and the data passing through.
Specialised builders
peek creates a context-sensitive computation that can look at the current context, but not modify it.
modify creates a context-sensitive computation that can look at and modify the current context.
val return : 'a -> 'a treturn lifts a value or monad into a stateful computation.
...as well as their runner functions...
...and fixed-point combinators.