in-other-words-0.2.1.0: A higher-order effect system where the sky's the limit
Safe HaskellNone
LanguageHaskell2010

Control.Effect.State

Synopsis

Effect

data State s :: Effect where Source #

An effect for non-atomic stateful operations.

If you need atomicity, use AtomicState instead.

Constructors

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

Actions

state :: Eff (State s) m => (s -> (s, a)) -> m a Source #

Read and modify the state.

The resulting tuple of the computation is forced. You can control what parts of the computation are evaluated by tying their evaluation to the tuple.

state' :: Eff (State s) m => (s -> (s, a)) -> m a Source #

A variant of state that forces the resulting state (but not the return value)

get :: Eff (State s) m => m s Source #

gets :: Eff (State s) m => (s -> a) -> m a Source #

put :: Eff (State s) m => s -> m () Source #

modify :: Eff (State s) m => (s -> s) -> m () Source #

modify' :: Eff (State s) m => (s -> s) -> m () Source #

A variant of modify that forces the resulting state.

Interpretations

runState :: forall s m a p. (Carrier m, Threaders '[StateThreads] m p) => s -> StateC s m a -> m (s, a) Source #

Runs a State s effect purely.

Derivs (StateC s m) = State s ': Derivs m
Prims  (StateC e m) = Prims m

evalState :: forall s m a p. (Carrier m, Threaders '[StateThreads] m p) => s -> StateC s m a -> m a Source #

Runs a State s effect purely, discarding the end state.

execState :: forall s m a p. (Carrier m, Threaders '[StateThreads] m p) => s -> StateC s m a -> m s Source #

Runs a State s effect purely, discarding the end result.

runStateLazy :: forall s m a p. (Carrier m, Threaders '[StateLazyThreads] m p) => s -> StateLazyC s m a -> m (s, a) Source #

Runs a State s effect purely and lazily.

Derivs (StateLazyC s m) = State s ': Derivs m
Prims  (StateLazyC e m) = Prims m

evalStateLazy :: forall s m a p. (Carrier m, Threaders '[StateLazyThreads] m p) => s -> StateLazyC s m a -> m a Source #

Runs a State s effect purely and lazily, discarding the final state.

execStateLazy :: forall s m a p. (Carrier m, Threaders '[StateLazyThreads] m p) => s -> StateLazyC s m a -> m s Source #

Runs a State s effect purely and lazily, discarding the end result.

stateToIO :: forall s m a. Eff (Embed IO) m => s -> InterpretReifiedC (State s) m a -> m (s, a) Source #

Runs a State s effect by transforming it into non-atomic operations in IO.

This has a higher-rank type, as it makes use of InterpretReifiedC. This makes stateToIO very difficult to use partially applied. In particular, it can't be composed using ..

If performance is secondary, consider using the slower stateToIOSimple, which doesn't have a higher-rank type.

runStateIORef :: forall s m a. Eff (Embed IO) m => IORef s -> InterpretReifiedC (State s) m a -> m a Source #

Runs a State s effect by transforming it into non-atomic operations over an IORef.

This has a higher-rank type, as it makes use of InterpretReifiedC. This makes runStateIORef very difficult to use partially applied. In particular, it can't be composed using ..

If performance is secondary, consider using the slower runStateIORefSimple, which doesn't have a higher-rank type.

Simple variants of interpretations

stateToIOSimple :: forall s m a p. (Eff (Embed IO) m, Threaders '[ReaderThreads] m p) => s -> InterpretSimpleC (State s) m a -> m (s, a) Source #

Runs a State s effect by transforming it into non-atomic operations in IO.

This is a less performant version of stateToIO that doesn't have a higher-rank type, making it much easier to use partially applied.

runStateIORefSimple :: forall s m a p. (Eff (Embed IO) m, Threaders '[ReaderThreads] m p) => IORef s -> InterpretSimpleC (State s) m a -> m a Source #

Runs a State s effect by transforming it into non-atomic operations over an IORef.

This is a less performant version of runStateIORef that doesn't have a higher-rank type, making it much easier to use partially applied.

Threading constraints

class (forall s. Threads (StateT s) p) => StateThreads p Source #

StateThreads accepts the following primitive effects:

Instances

Instances details
(forall s. Threads (StateT s) p) => StateThreads p Source # 
Instance details

Defined in Control.Effect.Internal.State

class (forall s. Threads (StateT s) p) => StateLazyThreads p Source #

StateLazyThreads accepts the following primitive effects:

Instances

Instances details
(forall s. Threads (StateT s) p) => StateLazyThreads p Source # 
Instance details

Defined in Control.Effect.Internal.State

Carriers

data StateC s m a Source #

Instances

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

Defined in Control.Effect.Internal.State

Methods

liftBase :: b α -> StateC s m α #

MonadBaseControl b m => MonadBaseControl b (StateC s m) Source # 
Instance details

Defined in Control.Effect.Internal.State

Associated Types

type StM (StateC s m) a #

Methods

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

restoreM :: StM (StateC s m) a -> StateC s m a #

MonadTrans (StateC s) Source # 
Instance details

Defined in Control.Effect.Internal.State

Methods

lift :: Monad m => m a -> StateC s m a #

MonadTransControl (StateC s) Source # 
Instance details

Defined in Control.Effect.Internal.State

Associated Types

type StT (StateC s) a #

Methods

liftWith :: Monad m => (Run (StateC s) -> m a) -> StateC s m a #

restoreT :: Monad m => m (StT (StateC s) a) -> StateC s m a #

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

Defined in Control.Effect.Internal.State

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.Effect.Internal.State

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.Effect.Internal.State

Methods

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

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

Defined in Control.Effect.Internal.State

Methods

fail :: String -> StateC s m a #

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

Defined in Control.Effect.Internal.State

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.Effect.Internal.State

Methods

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

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

Defined in Control.Effect.Internal.State

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] #

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

Defined in Control.Effect.Internal.State

Methods

mzero :: StateC s m a #

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

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

Defined in Control.Effect.Internal.State

Methods

throwM :: Exception e => e -> StateC s m a #

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

Defined in Control.Effect.Internal.State

Methods

catch :: Exception e => StateC s m a -> (e -> StateC s m a) -> StateC s m a #

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

Defined in Control.Effect.Internal.State

Methods

mask :: ((forall a. StateC s m a -> StateC s m a) -> StateC s m b) -> StateC s m b #

uninterruptibleMask :: ((forall a. StateC s m a -> StateC s m a) -> StateC s m b) -> StateC s m b #

generalBracket :: StateC s m a -> (a -> ExitCase b -> StateC s m c) -> (a -> StateC s m b) -> StateC s m (b, c) #

(Carrier m, Threads (StateT s) (Prims m)) => Carrier (StateC s m) Source # 
Instance details

Defined in Control.Effect.Internal.State

Associated Types

type Derivs (StateC s m) :: [Effect] Source #

type Prims (StateC s m) :: [Effect] Source #

Methods

algPrims :: Algebra' (Prims (StateC s m)) (StateC s m) a Source #

reformulate :: Monad z => Reformulation' (Derivs (StateC s m)) (Prims (StateC s m)) (StateC s m) z a Source #

algDerivs :: Algebra' (Derivs (StateC s m)) (StateC s m) a Source #

type StT (StateC s) a Source # 
Instance details

Defined in Control.Effect.Internal.State

type StT (StateC s) a = StT (StateT s) a
type Derivs (StateC s m) Source # 
Instance details

Defined in Control.Effect.Internal.State

type Derivs (StateC s m) = State s ': Derivs m
type Prims (StateC s m) Source # 
Instance details

Defined in Control.Effect.Internal.State

type Prims (StateC s m) = Prims m
type StM (StateC s m) a Source # 
Instance details

Defined in Control.Effect.Internal.State

type StM (StateC s m) a = StM (StateT s m) a

data StateLazyC s m a Source #

Instances

Instances details
MonadBase b m => MonadBase b (StateLazyC s m) Source # 
Instance details

Defined in Control.Effect.Internal.State

Methods

liftBase :: b α -> StateLazyC s m α #

MonadBaseControl b m => MonadBaseControl b (StateLazyC s m) Source # 
Instance details

Defined in Control.Effect.Internal.State

Associated Types

type StM (StateLazyC s m) a #

Methods

liftBaseWith :: (RunInBase (StateLazyC s m) b -> b a) -> StateLazyC s m a #

restoreM :: StM (StateLazyC s m) a -> StateLazyC s m a #

MonadTrans (StateLazyC s) Source # 
Instance details

Defined in Control.Effect.Internal.State

Methods

lift :: Monad m => m a -> StateLazyC s m a #

MonadTransControl (StateLazyC s) Source # 
Instance details

Defined in Control.Effect.Internal.State

Associated Types

type StT (StateLazyC s) a #

Methods

liftWith :: Monad m => (Run (StateLazyC s) -> m a) -> StateLazyC s m a #

restoreT :: Monad m => m (StT (StateLazyC s) a) -> StateLazyC s m a #

Monad m => Monad (StateLazyC s m) Source # 
Instance details

Defined in Control.Effect.Internal.State

Methods

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

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

return :: a -> StateLazyC s m a #

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

Defined in Control.Effect.Internal.State

Methods

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

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

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

Defined in Control.Effect.Internal.State

Methods

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

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

Defined in Control.Effect.Internal.State

Methods

fail :: String -> StateLazyC s m a #

Monad m => Applicative (StateLazyC s m) Source # 
Instance details

Defined in Control.Effect.Internal.State

Methods

pure :: a -> StateLazyC s m a #

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

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

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

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

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

Defined in Control.Effect.Internal.State

Methods

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

MonadPlus m => Alternative (StateLazyC s m) Source # 
Instance details

Defined in Control.Effect.Internal.State

Methods

empty :: StateLazyC s m a #

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

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

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

MonadPlus m => MonadPlus (StateLazyC s m) Source # 
Instance details

Defined in Control.Effect.Internal.State

Methods

mzero :: StateLazyC s m a #

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

MonadThrow m => MonadThrow (StateLazyC s m) Source # 
Instance details

Defined in Control.Effect.Internal.State

Methods

throwM :: Exception e => e -> StateLazyC s m a #

MonadCatch m => MonadCatch (StateLazyC s m) Source # 
Instance details

Defined in Control.Effect.Internal.State

Methods

catch :: Exception e => StateLazyC s m a -> (e -> StateLazyC s m a) -> StateLazyC s m a #

MonadMask m => MonadMask (StateLazyC s m) Source # 
Instance details

Defined in Control.Effect.Internal.State

Methods

mask :: ((forall a. StateLazyC s m a -> StateLazyC s m a) -> StateLazyC s m b) -> StateLazyC s m b #

uninterruptibleMask :: ((forall a. StateLazyC s m a -> StateLazyC s m a) -> StateLazyC s m b) -> StateLazyC s m b #

generalBracket :: StateLazyC s m a -> (a -> ExitCase b -> StateLazyC s m c) -> (a -> StateLazyC s m b) -> StateLazyC s m (b, c) #

(Carrier m, Threads (StateT s) (Prims m)) => Carrier (StateLazyC s m) Source # 
Instance details

Defined in Control.Effect.Internal.State

Associated Types

type Derivs (StateLazyC s m) :: [Effect] Source #

type Prims (StateLazyC s m) :: [Effect] Source #

type StT (StateLazyC s) a Source # 
Instance details

Defined in Control.Effect.Internal.State

type StT (StateLazyC s) a = StT (StateT s) a
type Derivs (StateLazyC s m) Source # 
Instance details

Defined in Control.Effect.Internal.State

type Derivs (StateLazyC s m) = State s ': Derivs m
type Prims (StateLazyC s m) Source # 
Instance details

Defined in Control.Effect.Internal.State

type Prims (StateLazyC s m) = Prims m
type StM (StateLazyC s m) a Source # 
Instance details

Defined in Control.Effect.Internal.State

type StM (StateLazyC s m) a = StM (StateT s m) a