bluefin-0.6.0.0: The Bluefin effect system
Safe HaskellNone
LanguageHaskell2010

Bluefin.State

Description

This is an old interface and will be deprecated in the future. You are encouraged to use Bluefin.Capability.Modify instead.

Synopsis

Handle

data State s (e :: Effects) Source #

Capability to modify a reference to an s

Instances

Instances details
e <: es => OneWayCoercible (State s e :: Type) (State s es :: Type) 
Instance details

Defined in Bluefin.Internal

Handle (State s) 
Instance details

Defined in Bluefin.Internal

CloneableHandle (State s)

Cloning a State copies its contents to a new State. Changes to one will not effect the other.

Instance details

Defined in Bluefin.Internal.CloneableHandle

Handlers

evalState Source #

Arguments

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

Initial state

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

Stateful computation

-> Eff es a

Result

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

runState Source #

Arguments

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

Initial state

-> (forall (e :: Effects). State s e -> Eff (e :& 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)

withState Source #

Arguments

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

Initial state

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

Stateful computation

-> Eff es a

Result

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

Effectful operations

get Source #

Arguments

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

The current value of the state

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

put Source #

Arguments

:: forall (e :: Effects) (es :: Effects) s. e <: es 
=> State s e 
-> 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 Source #

Arguments

:: forall (e :: Effects) (es :: Effects) s. e <: es 
=> State s e 
-> (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)