bluefin-0.0.3.0: The Bluefin effect system
Safe HaskellSafe-Inferred
LanguageHaskell2010

Bluefin.State

Synopsis

Handle

data State s (st :: Effects) #

A handle to a strict mutable state of type a

Handlers

evalState #

Arguments

:: forall s (es :: Effects) a. s

Initial state

-> (forall (st :: Effects). State s st -> Eff (st :& es) a)

Stateful computation

-> Eff es a

Result

>>> runPureEff $ evalState 10 $ \st -> do
      n <- get st
      pure (2 * n)
20

runState #

Arguments

:: forall s (es :: Effects) a. s

Initial state

-> (forall (st :: Effects). State s st -> Eff (st :& es) a)

Stateful computation

-> Eff es (a, s)

Result and final state

>>> runPureEff $ runState 10 $ \st -> do
      n <- get st
      pure (2 * n)
(20,10)

Effectful operations

get #

Arguments

:: forall (st :: Effects) (es :: Effects) s. st :> es 
=> State s st 
-> Eff es s

The current value of the state

>>> runPureEff $ runState 10 $ \st -> do
      n <- get st
      pure (2 * n)
(20,10)

put #

Arguments

:: forall (st :: Effects) (es :: Effects) s. st :> es 
=> State s st 
-> s

The new value of the state. The new value is forced before writing it to the state.

-> Eff es () 

Set the value of the state

>>> runPureEff $ runState 10 $ \st -> do
      put st 30
((), 30)

modify #

Arguments

:: forall (st :: Effects) (es :: Effects) s. st :> es 
=> State s st 
-> (s -> s)

Apply this function to the state. The new value of the state is forced before writing it to the state.

-> Eff es () 
>>> runPureEff $ runState 10 $ \st -> do
      modify st (* 2)
((), 20)