freer-simple-1.2.1.2: A friendly effect system for Haskell.
Copyright(c) 2016 Allele Dev; 2017 Ixperta Solutions s.r.o.; 2017 Alexis King
LicenseBSD3
MaintainerAlexis King <lexi.lambda@gmail.com>
Stabilityexperimental
PortabilityGHC specific language extensions.
Safe HaskellNone
LanguageHaskell2010

Control.Monad.Freer.State

Description

Composable handler for State effects. Handy for passing an updatable state through a computation.

Some computations may not require the full power of State effect:

Using http://okmij.org/ftp/Haskell/extensible/Eff1.hs as a starting point.

Synopsis

State Effect

data State s r where Source #

Strict State effects: one can either Get values or Put them.

Constructors

Get :: State s s 
Put :: !s -> State s () 

State Operations

get :: forall s effs. Member (State s) effs => Eff effs s Source #

Retrieve the current value of the state of type s :: *.

put :: forall s effs. Member (State s) effs => s -> Eff effs () Source #

Set the current state to a specified value of type s :: *.

modify :: forall s effs. Member (State s) effs => (s -> s) -> Eff effs () Source #

Modify the current state of type s :: * using provided function (s -> s).

gets :: forall s a effs. Member (State s) effs => (s -> a) -> Eff effs a Source #

Retrieve a specific component of the current state using the provided projection function.

State Handlers

runState :: forall s effs a. s -> Eff (State s ': effs) a -> Eff effs (a, s) Source #

Handler for State effects.

evalState :: forall s effs a. s -> Eff (State s ': effs) a -> Eff effs a Source #

Run a State effect, discarding the final state.

execState :: forall s effs a. s -> Eff (State s ': effs) a -> Eff effs s Source #

Run a State effect, returning only the final state.

State Utilities

transactionState :: forall s effs a. Member (State s) effs => Eff effs a -> Eff effs a Source #

An encapsulated State handler, for transactional semantics. The global state is updated only if the transactionState finished successfully.

GHC cannot infer the s type parameter for this function, so it must be specified explicitly with TypeApplications. Alternatively, it can be specified by supplying a Proxy to transactionState'.

transactionState' :: forall s effs a. Member (State s) effs => Proxy s -> Eff effs a -> Eff effs a Source #

Like transactionState, but s is specified by providing a Proxy instead of requiring TypeApplications.