fused-effects-exceptions-1.1.0.1: Handle exceptions thrown in IO with fused-effects.
Safe HaskellNone
LanguageHaskell2010

Control.Carrier.State.IORef

Description

A carrier for the State effect. It uses an IORef internally to handle its state, and thus is safe to use with Control.Carrier.Resource. Underlying IORef operations are performed with readIORef and writeIORef.

Note that the parameter order in runState, evalState, and execState is reversed compared the equivalent functions provided by transformers. This is an intentional decision made to enable the composition of effect handlers with . without invoking flip.

Synopsis

Strict state carrier

runState :: MonadIO m => s -> StateC s m a -> m (s, a) Source #

Run a State effect starting from the passed value.

run (runState a (pure b)) === (a, b)

Since: 1.0.0.0

evalState :: forall s m a. MonadIO m => s -> StateC s m a -> m a Source #

Run a State effect, yielding the result value and discarding the final state.

run (evalState a (pure b)) === b

Since: 1.0.0.0

execState :: forall s m a. MonadIO m => s -> StateC s m a -> m s Source #

Run a State effect, yielding the final state and discarding the return value.

run (execState a (pure b)) === a

Since: 1.0.0.0

newtype StateC s m a Source #

Since: 1.0.0.0

Constructors

StateC 

Fields

Instances

Instances details
Monad m => Monad (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.IORef

Methods

(>>=) :: StateC s m a -> (a -> StateC s m b) -> StateC s m b #

(>>) :: StateC s m a -> StateC s m b -> StateC s m b #

return :: a -> StateC s m a #

Functor m => Functor (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.IORef

Methods

fmap :: (a -> b) -> StateC s m a -> StateC s m b #

(<$) :: a -> StateC s m b -> StateC s m a #

MonadFix m => MonadFix (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.IORef

Methods

mfix :: (a -> StateC s m a) -> StateC s m a #

MonadFail m => MonadFail (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.IORef

Methods

fail :: String -> StateC s m a #

Applicative m => Applicative (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.IORef

Methods

pure :: a -> StateC s m a #

(<*>) :: StateC s m (a -> b) -> StateC s m a -> StateC s m b #

liftA2 :: (a -> b -> c) -> StateC s m a -> StateC s m b -> StateC s m c #

(*>) :: StateC s m a -> StateC s m b -> StateC s m b #

(<*) :: StateC s m a -> StateC s m b -> StateC s m a #

MonadIO m => MonadIO (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.IORef

Methods

liftIO :: IO a -> StateC s m a #

Alternative m => Alternative (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.IORef

Methods

empty :: StateC s m a #

(<|>) :: StateC s m a -> StateC s m a -> StateC s m a #

some :: StateC s m a -> StateC s m [a] #

many :: StateC s m a -> StateC s m [a] #

(Alternative m, Monad m) => MonadPlus (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.IORef

Methods

mzero :: StateC s m a #

mplus :: StateC s m a -> StateC s m a -> StateC s m a #

(MonadIO m, Algebra sig m) => Algebra (State s :+: sig) (StateC s m) Source # 
Instance details

Defined in Control.Carrier.State.IORef

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (StateC s m) -> (State s :+: sig) n a -> ctx () -> StateC s m (ctx a) #

State effect