monadology-0.3: The best ideas in monad-related classes and types.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Monad.Ology.Specific.StateT

Synopsis

Documentation

evalState #

Arguments

:: State s a

state-passing computation to execute

-> s

initial value

-> a

return value of the state computation

Evaluate a state computation with the given initial state and return the final value, discarding the final state.

evalStateT :: Monad m => StateT s m a -> s -> m a #

Evaluate a state computation with the given initial state and return the final value, discarding the final state.

execState #

Arguments

:: State s a

state-passing computation to execute

-> s

initial value

-> s

final state

Evaluate a state computation with the given initial state and return the final state, discarding the final value.

execStateT :: Monad m => StateT s m a -> s -> m s #

Evaluate a state computation with the given initial state and return the final state, discarding the final value.

mapState :: ((a, s) -> (b, s)) -> State s a -> State s b #

Map both the return value and final state of a computation using the given function.

mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b #

Map both the return value and final state of a computation using the given function.

runState #

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.)

withState :: (s -> s) -> State s a -> State s a #

withState f m executes action m on a state modified by applying f.

withStateT :: forall s (m :: Type -> Type) a. (s -> s) -> StateT s m a -> StateT s m a #

withStateT f m executes action m on a state modified by applying f.

type State s = StateT s Identity #

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.

newtype StateT s (m :: Type -> Type) a #

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.

Constructors

StateT 

Fields

Instances

Instances details
TransConstraint MonadFail (StateT s) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

Methods

hasTransConstraint :: forall (m :: Type -> Type). MonadFail m => Dict (MonadFail (StateT s m)) Source #

TransConstraint MonadFix (StateT s) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

Methods

hasTransConstraint :: forall (m :: Type -> Type). MonadFix m => Dict (MonadFix (StateT s m)) Source #

TransConstraint MonadIO (StateT s) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

Methods

hasTransConstraint :: forall (m :: Type -> Type). MonadIO m => Dict (MonadIO (StateT s m)) Source #

TransConstraint Functor (StateT s) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

Methods

hasTransConstraint :: forall (m :: Type -> Type). Functor m => Dict (Functor (StateT s m)) Source #

TransConstraint Monad (StateT s) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

Methods

hasTransConstraint :: forall (m :: Type -> Type). Monad m => Dict (Monad (StateT s m)) Source #

TransConstraint MonadPlus (StateT s) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

Methods

hasTransConstraint :: forall (m :: Type -> Type). MonadPlus m => Dict (MonadPlus (StateT s m)) Source #

TransConstraint MonadException (StateT s) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

Methods

hasTransConstraint :: forall (m :: Type -> Type). MonadException m => Dict (MonadException (StateT s m)) Source #

MonadCatch e m => MonadCatch e (StateT s m) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

Methods

catch :: StateT s m a -> (e -> StateT s m a) -> StateT s m a Source #

MonadThrow e m => MonadThrow e (StateT s m) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

Methods

throw :: e -> StateT s m a Source #

MonadTransCoerce (StateT a) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

Methods

transCoerce :: forall (m1 :: Type -> Type) (m2 :: Type -> Type). Coercible m1 m2 => Dict (Coercible (StateT a m1) (StateT a m2)) Source #

MonadTransHoist (StateT s) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

Methods

hoist :: forall (m1 :: Type -> Type) (m2 :: Type -> Type). (Monad m1, Monad m2) => (m1 --> m2) -> StateT s m1 --> StateT s m2 Source #

MonadTransTunnel (StateT s) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

Associated Types

type Tunnel (StateT s) :: Type -> Type Source #

Methods

tunnel :: Monad m => ((forall (m1 :: Type -> Type) a. Monad m1 => StateT s m1 a -> m1 (Tunnel (StateT s) a)) -> m (Tunnel (StateT s) r)) -> StateT s m r Source #

MonadTransUnlift (StateT s) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

Methods

liftWithUnlift :: MonadIO m => (Unlift MonadTunnelIO (StateT s) -> m r) -> StateT s m r Source #

getDiscardingUnlift :: forall (m :: Type -> Type). Monad m => StateT s m (WUnlift MonadTunnelIO (StateT s)) Source #

MonadTrans (StateT s) 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

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

TransConstraint (MonadCatch e) (StateT s) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

Methods

hasTransConstraint :: forall (m :: Type -> Type). MonadCatch e m => Dict (MonadCatch e (StateT s m)) Source #

TransConstraint (MonadThrow e) (StateT s) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

Methods

hasTransConstraint :: forall (m :: Type -> Type). MonadThrow e m => Dict (MonadThrow e (StateT s m)) Source #

MonadFail m => MonadFail (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

fail :: String -> StateT s m a #

MonadFix m => MonadFix (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

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

MonadIO m => MonadIO (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

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

Contravariant m => Contravariant (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

contramap :: (a' -> a) -> StateT s m a -> StateT s m a' #

(>$) :: b -> StateT s m b -> StateT s m a #

(Functor m, MonadPlus m) => Alternative (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

empty :: StateT s m a #

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

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

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

(Functor m, Monad m) => Applicative (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

pure :: a -> StateT s m a #

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

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

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

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

Functor m => Functor (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

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

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

Monad m => Monad (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

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

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

return :: a -> StateT s m a #

MonadPlus m => MonadPlus (StateT s m) 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

mzero :: StateT s m a #

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

Invariant m => Invariant (StateT s m)

from the transformers package

Instance details

Defined in Data.Functor.Invariant

Methods

invmap :: (a -> b) -> (b -> a) -> StateT s m a -> StateT s m b #

MonadException m => MonadException (StateT s m) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

Associated Types

type Exc (StateT s m) Source #

Methods

throwExc :: Exc (StateT s m) -> StateT s m a Source #

catchExc :: StateT s m a -> (Exc (StateT s m) -> StateT s m a) -> StateT s m a Source #

type Tunnel (StateT s) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

type Tunnel (StateT s) = (,) (Endo s)
type Exc (StateT s m) Source # 
Instance details

Defined in Control.Monad.Ology.Specific.StateT

type Exc (StateT s m) = Exc m

state #

Arguments

:: forall (m :: Type -> Type) s a. Monad m 
=> (s -> (a, s))

pure state transformer

-> StateT s m a

equivalent state-passing computation

Construct a state monad computation from a function. (The inverse of runState.)

put :: forall (m :: Type -> Type) s. Monad m => s -> StateT s m () #

put s sets the state within the monad to s.

modify' :: forall (m :: Type -> Type) s. Monad m => (s -> s) -> StateT s m () #

A variant of modify in which the computation is strict in the new state.

modify :: forall (m :: Type -> Type) s. Monad m => (s -> s) -> StateT s m () #

modify f is an action that updates the state to the result of applying f to the current state.

liftCallCC' :: CallCC m (a, s) (b, s) -> CallCC (StateT s m) a b #

In-situ lifting of a callCC operation to the new monad. This version uses the current state on entering the continuation. It does not satisfy the uniformity property (see Control.Monad.Signatures).

gets :: forall (m :: Type -> Type) s a. Monad m => (s -> a) -> StateT s m a #

Get a specific component of the state, using a projection function supplied.

get :: forall (m :: Type -> Type) s. Monad m => StateT s m s #

Fetch the current value of the state within the monad.

mVarRunStateT :: MVar s -> Unlift MonadTunnelIO (StateT s) Source #

Run the StateT on an MVar, taking the initial state and putting the final state.

mVarRunLocked :: MonadTunnelIO m => MVar s -> m --> m Source #

Take the MVar before and put it back after.

dangerousMVarRunStateT :: MVar s -> Unlift MonadIO (StateT s) Source #

Dangerous, because the MVar won't be released on exception.

liftStateT :: (Traversable f, Applicative m) => StateT s m a -> StateT (f s) m (f a) Source #

liftWithMVarStateT :: MonadIO m => (MVar s -> m a) -> StateT s m a Source #

Orphan instances

TransConstraint MonadFail (StateT s) Source # 
Instance details

Methods

hasTransConstraint :: forall (m :: Type -> Type). MonadFail m => Dict (MonadFail (StateT s m)) Source #

TransConstraint MonadFix (StateT s) Source # 
Instance details

Methods

hasTransConstraint :: forall (m :: Type -> Type). MonadFix m => Dict (MonadFix (StateT s m)) Source #

TransConstraint MonadIO (StateT s) Source # 
Instance details

Methods

hasTransConstraint :: forall (m :: Type -> Type). MonadIO m => Dict (MonadIO (StateT s m)) Source #

TransConstraint Functor (StateT s) Source # 
Instance details

Methods

hasTransConstraint :: forall (m :: Type -> Type). Functor m => Dict (Functor (StateT s m)) Source #

TransConstraint Monad (StateT s) Source # 
Instance details

Methods

hasTransConstraint :: forall (m :: Type -> Type). Monad m => Dict (Monad (StateT s m)) Source #

TransConstraint MonadPlus (StateT s) Source # 
Instance details

Methods

hasTransConstraint :: forall (m :: Type -> Type). MonadPlus m => Dict (MonadPlus (StateT s m)) Source #

TransConstraint MonadException (StateT s) Source # 
Instance details

Methods

hasTransConstraint :: forall (m :: Type -> Type). MonadException m => Dict (MonadException (StateT s m)) Source #

MonadCatch e m => MonadCatch e (StateT s m) Source # 
Instance details

Methods

catch :: StateT s m a -> (e -> StateT s m a) -> StateT s m a Source #

MonadThrow e m => MonadThrow e (StateT s m) Source # 
Instance details

Methods

throw :: e -> StateT s m a Source #

MonadTransCoerce (StateT a) Source # 
Instance details

Methods

transCoerce :: forall (m1 :: Type -> Type) (m2 :: Type -> Type). Coercible m1 m2 => Dict (Coercible (StateT a m1) (StateT a m2)) Source #

MonadTransHoist (StateT s) Source # 
Instance details

Methods

hoist :: forall (m1 :: Type -> Type) (m2 :: Type -> Type). (Monad m1, Monad m2) => (m1 --> m2) -> StateT s m1 --> StateT s m2 Source #

MonadTransTunnel (StateT s) Source # 
Instance details

Associated Types

type Tunnel (StateT s) :: Type -> Type Source #

Methods

tunnel :: Monad m => ((forall (m1 :: Type -> Type) a. Monad m1 => StateT s m1 a -> m1 (Tunnel (StateT s) a)) -> m (Tunnel (StateT s) r)) -> StateT s m r Source #

MonadTransUnlift (StateT s) Source # 
Instance details

Methods

liftWithUnlift :: MonadIO m => (Unlift MonadTunnelIO (StateT s) -> m r) -> StateT s m r Source #

getDiscardingUnlift :: forall (m :: Type -> Type). Monad m => StateT s m (WUnlift MonadTunnelIO (StateT s)) Source #

TransConstraint (MonadCatch e) (StateT s) Source # 
Instance details

Methods

hasTransConstraint :: forall (m :: Type -> Type). MonadCatch e m => Dict (MonadCatch e (StateT s m)) Source #

TransConstraint (MonadThrow e) (StateT s) Source # 
Instance details

Methods

hasTransConstraint :: forall (m :: Type -> Type). MonadThrow e m => Dict (MonadThrow e (StateT s m)) Source #

MonadException m => MonadException (StateT s m) Source # 
Instance details

Associated Types

type Exc (StateT s m) Source #

Methods

throwExc :: Exc (StateT s m) -> StateT s m a Source #

catchExc :: StateT s m a -> (Exc (StateT s m) -> StateT s m a) -> StateT s m a Source #