package orsetto
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=151ca6df499bd3de7aa89a4e1627411fbee24c4dea6e0e71ce21f06f181ee654
md5=00393728b481c2bf15919a8202732335
doc/orsetto.cf/Cf_scmonad/index.html
Module Cf_scmonad
The state-continuation monad and its operators.
Overview
The state-continuation monad is the composition of the continuation monad and the state monad: a function for passing intermediate results from continuation context to continuation context with an encapsulated state value at each stage.
Types
type ('s, 'x, 'r) t = ('s -> 'x, 'r) Cf_cmonad.t
The state-continuation monad type.
module Basis :
Cf_monad.Trinary.Basis with type ('s, 'x, 'r) t := ('s, 'x, 'r) t
include Cf_monad.Trinary.Profile with type ('s, 'x, 'r) t := ('s, 'x, 'r) t
Module inclusions from Cf_monad_core
and Cf_seqmonad
.
include Cf_monad.Core.Trinary.Profile
with type ('p, 'q, 'r) t := ('p, 'q, 'r) t
val return : 'r -> ('p, 'q, 'r) t
Use return a
to apply the binding to a
.
Use bind m f
to bind f
to the value returned by m
.
Use map m f
to return the result of applying f
to the value returned by m
.
module Infix :
Cf_monad_core.Trinary.Infix with type ('p, 'q, 'r) t := ('p, 'q, 'r) t
Open Infix
to include the infix monad operators.
include Cf_seqmonad.Functor.Trinary with type ('p, 'q, 'r) t := ('p, 'q, 'r) t
Use collect s
to bind in sequence every monad value in the finite sequence s
and collect all the returned values. Returns (n, s)
where n
is the number of values collected and s
is the list of values in reverse order, i.e. from last collected to first collected. Never returns and exhausts all memory if s
never terminates.
Operators
val nil : ('s, 'x, unit) t
A monad that returns unit
and performs no operation.
val init : 'x -> ('s, 'x, 'r) t
Use init x
to produce a monad that discards the current intermediate context and passes x
into the continuation.
val cont : ('x -> 'x) -> ('s, 'x, unit) t
Use cont f
to produce a monad that applies f
to the current intermediate context and passes the result into the continuation.
val load : ('s, 'x, 's) t
A monad that returns the encapsulate state.
val store : 's -> ('s, 'x, unit) t
Use store s
to produce a monad with s
as the encapsulated state.
val modify : ('s -> 's) -> ('s, 'x, unit) t
Use modify f
to produce a monad that applies f
to the encapsulated state to obtain a new state value.
val field : ('s -> 'r) -> ('s, 'x, 'r) t
Use field f
to produce a monad that applies f
to the encapsulated state and returns the result.
val downC : ('s, 'x, unit) t -> 's -> ('x, 's) Cf_cmonad.t
Use downC m s
to lower m
initialized with state s
into a continuation monad that returns the final state.
val downS : ('s, 'x, unit) t -> 'x -> ('s, 'x) Cf_smonad.t
Use downS m x
to lower m
initialized with context x
into a state monad that returns the final context without modifying the encapsulated state.
val liftC : ('x, 'r) Cf_cmonad.t -> ('s, 'x, 'r) t
Use liftC m
to lift a stateless continuation monad m
into a state-continuation monad.
val liftS : ('s, 'r) Cf_smonad.t -> ('s, 'x, 'r) t
Use liftS m
to lift a state monad m
into a state-continuation monad.
val eval : ('s, 'x, unit) t -> 's -> 'x -> 'x
Use eval m s
to evaluate the state-continuation monad m
with initial state s
to produce a function from an initial context to a final context.
Use bridge x f m
to lower the state-continuation monad m
, then bridge with the initial context x
and a map function f
, and finally lift the result to another state-contination monad, one that evaluates m
using the state bridged from the result monad.