bluefin-algae-0.1.0.1: Algebraic effects and named handlers in Bluefin.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Bluefin.Algae.State

Description

State as an algebraic effect

The runState handler calls each continuation exactly once. It is compatible with single-shot continuations.

Synopsis

Operations

data State (s :: Type) :: AEffect where Source #

The state effect.

Constructors

Get :: State s s

Get the current state.

Put :: s -> State s ()

Put a new state.

get :: z :> zz => Handler (State s) z -> Eff zz s Source #

Get the current state. Call the Get operation.

put :: z :> zz => Handler (State s) z -> s -> Eff zz () Source #

Put a new state. Call the Put operation.

This function is strict.

putL :: z :> zz => Handler (State s) z -> s -> Eff zz () Source #

Lazy variant of put.

modify :: z :> zz => Handler (State s) z -> (s -> s) -> Eff zz () Source #

Modify the state.

This function is strict in the modified state.

modifyL :: z :> zz => Handler (State s) z -> (s -> s) -> Eff zz () Source #

Lazy variant of modify.

Handlers

runState Source #

Arguments

:: s

Initial state

-> (forall z. Handler (State s) z -> Eff (z :& zz) a)

Stateful computation

-> Eff zz (a, s) 

Run a stateful computation from the given starting state.

evalState Source #

Arguments

:: s

Initial state

-> (forall z. Handler (State s) z -> Eff (z :& zz) a)

Stateful computation

-> Eff zz a 

Variant of runState that returns only the result value.

execState Source #

Arguments

:: s

Initial state

-> (forall z. Handler (State s) z -> Eff (z :& zz) a)

Stateful computation

-> Eff zz s 

Variant of runState that returns only the final state.