| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
RIO.State
Description
Provides reexports of MonadState and related helpers.
Since: 0.1.4.0
Synopsis
- class Monad m => MonadState s (m :: Type -> Type) | m -> s where
- gets :: MonadState s m => (s -> a) -> m a
- modify :: MonadState s m => (s -> s) -> m ()
- modify' :: MonadState s m => (s -> s) -> m ()
- type State s = StateT s Identity
- runState :: State s a -> s -> (a, s)
- evalState :: State s a -> s -> a
- execState :: State s a -> s -> s
- mapState :: ((a, s) -> (b, s)) -> State s a -> State s b
- withState :: (s -> s) -> State s a -> State s a
- newtype StateT s (m :: Type -> Type) a = StateT {
- runStateT :: s -> m (a, s)
- evalStateT :: Monad m => StateT s m a -> s -> m a
- execStateT :: Monad m => StateT s m a -> s -> m s
- mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
- withStateT :: forall s (m :: Type -> Type) a. (s -> s) -> StateT s m a -> StateT s m a
Documentation
class Monad m => MonadState s (m :: Type -> Type) | m -> s where Source #
Minimal definition is either both of get and put or just state
Methods
Return the state from the internals of the monad.
Replace the state inside the monad.
state :: (s -> (a, s)) -> m a Source #
Embed a simple state action into the monad.
Instances
| MonadState s m => MonadState s (CatchT m) | |
| HasStateRef s env => MonadState s (RIO env) Source # | |
| MonadState s m => MonadState s (MaybeT m) | |
| (Monoid w, MonadState s m) => MonadState s (AccumT w m) | Since: mtl-2.3 |
| MonadState s m => MonadState s (ExceptT e m) | Since: mtl-2.2 |
| MonadState s m => MonadState s (IdentityT m) | |
| MonadState s m => MonadState s (ReaderT r m) | |
| MonadState s m => MonadState s (SelectT r m) | Since: mtl-2.3 |
| Monad m => MonadState s (StateT s m) | |
| Monad m => MonadState s (StateT s m) | |
| (Monoid w, MonadState s m) => MonadState s (WriterT w m) | Since: mtl-2.3 |
| (Monoid w, MonadState s m) => MonadState s (WriterT w m) | |
| (Monoid w, MonadState s m) => MonadState s (WriterT w m) | |
| MonadState s m => MonadState s (ContT r m) | |
| (Monad m, Monoid w) => MonadState s (RWST r w s m) | Since: mtl-2.3 |
| (Monad m, Monoid w) => MonadState s (RWST r w s m) | |
| (Monad m, Monoid w) => MonadState s (RWST r w s m) | |
gets :: MonadState s m => (s -> a) -> m a Source #
Gets specific component of the state, using a projection function supplied.
modify :: MonadState s m => (s -> s) -> m () Source #
Monadic state transformer.
Maps an old state to a new state inside a state monad. The old state is thrown away.
Main> :t modify ((+1) :: Int -> Int)
modify (...) :: (MonadState Int a) => a ()This says that modify (+1) acts over any
Monad that is a member of the MonadState class,
with an Int state.
modify' :: MonadState s m => (s -> s) -> m () Source #
A variant of modify in which the computation is strict in the
new state.
Since: mtl-2.2
type State s = StateT s Identity Source #
A state monad parameterized by the type s of the state to carry.
The return function leaves the state unchanged, while >>= uses
the final state of the first computation as the initial state of
the second.
Arguments
| :: State s a | state-passing computation to execute |
| -> s | initial state |
| -> (a, s) | return value and final state |
Unwrap a state monad computation as a function.
(The inverse of state.)
Arguments
| :: State s a | state-passing computation to execute |
| -> s | initial value |
| -> a | return value of the state computation |
Arguments
| :: State s a | state-passing computation to execute |
| -> s | initial value |
| -> s | final state |
newtype StateT s (m :: Type -> Type) a Source #
A state transformer monad parameterized by:
s- The state.m- The inner monad.
The return function leaves the state unchanged, while >>= uses
the final state of the first computation as the initial state of
the second.
Instances
| MonadAccum w m => MonadAccum w (StateT s m) | Since: mtl-2.3 | ||||
| MonadError e m => MonadError e (StateT s m) | |||||
Defined in Control.Monad.Error.Class Methods throwError :: e -> StateT s m a Source # catchError :: StateT s m a -> (e -> StateT s m a) -> StateT s m a Source # | |||||
| MonadReader r m => MonadReader r (StateT s m) | |||||
| MonadSelect w m => MonadSelect w (StateT s m) | 'Readerizes' the state: the 'ranking' function can see a value of
type Since: mtl-2.3 | ||||
Defined in Control.Monad.Select | |||||
| Monad m => MonadState s (StateT s m) | |||||
| MonadWriter w m => MonadWriter w (StateT s m) | |||||
| MonadTrans (StateT s) | |||||
| MonadIO m => MonadIO (StateT s m) | |||||
| Contravariant m => Contravariant (StateT s m) | |||||
| MonadCatch m => MonadCatch (StateT s m) | |||||
Defined in Control.Monad.Catch | |||||
| MonadMask m => MonadMask (StateT s m) | |||||
Defined in Control.Monad.Catch Methods mask :: HasCallStack => ((forall a. StateT s m a -> StateT s m a) -> StateT s m b) -> StateT s m b Source # uninterruptibleMask :: HasCallStack => ((forall a. StateT s m a -> StateT s m a) -> StateT s m b) -> StateT s m b Source # generalBracket :: HasCallStack => StateT s m a -> (a -> ExitCase b -> StateT s m c) -> (a -> StateT s m b) -> StateT s m (b, c) Source # | |||||
| MonadThrow m => MonadThrow (StateT s m) | |||||
Defined in Control.Monad.Catch | |||||
| (Functor m, MonadPlus m) => Alternative (StateT s m) | |||||
| (Functor m, Monad m) => Applicative (StateT s m) | |||||
Defined in Control.Monad.Trans.State.Lazy Methods pure :: a -> StateT s m a Source # (<*>) :: StateT s m (a -> b) -> StateT s m a -> StateT s m b Source # liftA2 :: (a -> b -> c) -> StateT s m a -> StateT s m b -> StateT s m c Source # (*>) :: StateT s m a -> StateT s m b -> StateT s m b Source # (<*) :: StateT s m a -> StateT s m b -> StateT s m a Source # | |||||
| Functor m => Functor (StateT s m) | |||||
| Monad m => Monad (StateT s m) | |||||
| MonadPlus m => MonadPlus (StateT s m) | |||||
| MonadFail m => MonadFail (StateT s m) | |||||
| MonadFix m => MonadFix (StateT s m) | |||||
| MonadCont m => MonadCont (StateT s m) | |||||
| PrimMonad m => PrimMonad (StateT s m) | |||||
| Monad z => Zoom (StateT s z) (StateT t z) s t | |||||
| Generic (StateT s m a) | |||||
Defined in Control.Monad.Trans.State.Lazy Associated Types
| |||||
| type Zoomed (StateT s z) | |||||
Defined in Lens.Micro.Mtl.Internal | |||||
| type PrimState (StateT s m) | |||||
Defined in Control.Monad.Primitive | |||||
| type Rep (StateT s m a) | |||||
Defined in Control.Monad.Trans.State.Lazy | |||||
evalStateT :: Monad m => StateT s m a -> s -> m a Source #
Evaluate a state computation with the given initial state and return the final value, discarding the final state.
evalStateTm s =liftMfst(runStateTm s)
execStateT :: Monad m => StateT s m a -> s -> m s Source #
Evaluate a state computation with the given initial state and return the final state, discarding the final value.
execStateTm s =liftMsnd(runStateTm s)
withStateT :: forall s (m :: Type -> Type) a. (s -> s) -> StateT s m a -> StateT s m a Source #
executes action withStateT f mm on a state modified by
applying f.
withStateTf m =modifyf >> m