std.state

Modules

The state monad.

Types

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

Values

let applicative : forall s . std.applicative.Applicative (std.state.State s)

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

let functor : forall s . std.functor.Functor (std.state.State s)

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

let monad : forall s . std.monad.Monad (std.state.State s)

A generalised interface for imperatively sequencing actions

let put value : forall s . s -> std.state.State s ()

let get : forall s . std.state.State s s

let modify f : forall s . (s -> s) -> std.state.State s ()

let runState f state : forall a s . std.state.State s a -> s -> { value : a, state : s }

let evalState f state : forall a s . std.state.State s a -> s -> a

let execState f state : forall a s . std.state.State s a -> s -> s