package preface

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

Operation of State monad parametrized over an inner monad and state.

type state

The encapsulated state.

type 'a monad

The inner monad.

type 'a t = state -> ('a * state) monad

The type held by the state monad.

val upper : 'a monad -> 'a t

promote monad into the transformation.

val eval : 'a t -> state -> 'a monad

Unwrap the state computation and extract the current value.

val exec : 'a t -> state -> state monad

Unwrap the state computation and extract the current state.

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

Unwrap the state computation.

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

Lift a function into a state.

val get : state t

Returns the current state.

val set : state -> unit t

Replace the state with the given one.

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

Modify the state applying the given function.

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

Apply a function to the current state and return it.