package bap-std

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

Result Monad Transformer.

module STM = Monad.T.State.Make(M) is not a monad M, but a state monad which build computations that are interleaved with computations of monad M. For example, let's take the Future as the outer monad:

module STF = Monad.T.State.Make(Future) will build a computation that can access values that are defined in the future, as a consequence, STF.run result will be a value that would be defined in the future. The computation built with STF monad will not try to access any future values until run is called. Once it is called, each step of the computation will first wait until the future occurs (i.e., future value is defined) and then perform update of the state.

As an another example, given some IO monad, a computation built with monad STIO = Monad.T.State.Make(IO) will not perform any I/O until it is actually ran or evaluated. And the result of the run would be ('a,'s) IO.t, that actually may not perform actual IO (i.e., system calls) until it is run (this, of course, depends on the implementation of IO, as Core.Async will not perform any operations until the scheduler is run, but Lwt will trigger the I/O and defer until it is finished).

Note: We do not provide Make2 because its result would be a module of non-existent Monad.S3 type.

module Make (M : S) : State.S with type 'a result = 'a M.t
OCaml

Innovation. Community. Security.