std.state

The state monad.

Types

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

Values

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

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 a . std.functor.Functor (std.state.State a)

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 a . std.monad.Monad (std.state.State a)

A generalised interface for imperatively sequencing actions

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

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

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

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

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

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