std.statet

The state monad transformer.

Types

type StateT s m a = s -> m { value : a, state : s }

Values

#[implicit]
let applicative ?mo : forall s m . [Monad m] -> Applicative (StateT s m)

A Functor with application.

The following laws should hold:

  • wrap id <*> v = v
  • wrap (<<) <*> u <*> v <*> w = u <*> (v <*> w)
  • wrap f <*> wrap x = wrap (f x)
  • u <*> wrap y = wrap (\g -> g x) <*> u

#[implicit]
let functor : forall s m . [Functor m] -> Functor (StateT s m)

A Functor represents an action on a parameterized type which does not change the structure with the mapped type.

The following laws should hold:

  • map id == id
  • map (f << g) == map f << map g

#[implicit]
let monad : forall s m . [Monad m] -> Monad (StateT s m)

A generalised interface for imperatively sequencing actions

#[implicit]
let transformer : forall s . Transformer (StateT s)

#[implicit]
let alternative : forall s m . [Monad m] -> [Alternative m] -> Alternative (StateT s m)

A monoid on applicative functors.

let put value : forall s m . [Monad m] -> s -> StateT s m ()

let get : forall s m . [Monad m] -> StateT s m s

let gets f : forall a s m . [Monad m] -> (s -> a) -> StateT s m a

let modify f : forall s m . [Monad m] -> (s -> s) -> StateT s m ()

let run_state_t f state : forall a m s . StateT s m a -> s -> m { value : a, state : s }

let eval_state_t f state : forall a s m . [Functor m] -> StateT s m a -> s -> m a

let exec_state_t f state : forall a s m . [Functor m] -> StateT s m a -> s -> m s