multistate-0.8.0.3: like mtl's ReaderT / WriterT / StateT, but more than one contained value/type.

Safe Haskell | Safe
Language | Haskell2010

Control.Monad.Trans.MultiState

Contents

- MultiStateT
- MonadMultiState class
- run-functions
- with-functions (single state)
- with-functions (multiple states)
- without-function (single state)
- inflate-functions (run single state in multiple states)
- other functions

Description

The multi-valued version of mtl's State / StateT / MonadState

Synopsis

- newtype MultiStateT x m a = MultiStateT {
  - runMultiStateTRaw :: StateT (HList x) m a
  }
- type MultiStateTNull = MultiStateT '[]
- type MultiState x = MultiStateT x Identity
- class Monad m => MonadMultiGet a m where
  - mGet :: m a
- class MonadMultiGet a m => MonadMultiState a m where
  - mSet :: a -> m ()
- runMultiStateT :: Functor m => HList s -> MultiStateT s m a -> m (a, HList s)
- runMultiStateTAS :: Functor m => HList s -> MultiStateT s m a -> m (a, HList s)
- runMultiStateTSA :: Monad m => HList s -> MultiStateT s m a -> m (HList s, a)
- runMultiStateTA :: Monad m => HList s -> MultiStateT s m a -> m a
- runMultiStateTS :: Monad m => HList s -> MultiStateT s m a -> m (HList s)
- runMultiStateT_ :: Functor m => HList s -> MultiStateT s m a -> m ()
- runMultiStateTNil :: Monad m => MultiStateT '[] m a -> m a
- runMultiStateTNil_ :: Functor m => MultiStateT '[] m a -> m ()
- withMultiState :: Monad m => s -> MultiStateT (s ': ss) m a -> MultiStateT ss m (a, s)
- withMultiStateAS :: Monad m => s -> MultiStateT (s ': ss) m a -> MultiStateT ss m (a, s)
- withMultiStateSA :: Monad m => s -> MultiStateT (s ': ss) m a -> MultiStateT ss m (s, a)
- withMultiStateA :: Monad m => s -> MultiStateT (s ': ss) m a -> MultiStateT ss m a
- withMultiStateS :: Monad m => s -> MultiStateT (s ': ss) m a -> MultiStateT ss m s
- withMultiState_ :: (Functor m, Monad m) => s -> MultiStateT (s ': ss) m a -> MultiStateT ss m ()
- withMultiStates :: Monad m => HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (a, HList s1)
- withMultiStatesAS :: Monad m => HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (a, HList s1)
- withMultiStatesSA :: Monad m => HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (HList s1, a)
- withMultiStatesA :: Monad m => HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m a
- withMultiStatesS :: Monad m => HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (HList s1)
- withMultiStates_ :: (Functor m, Monad m) => HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m ()
- withoutMultiState :: (Functor m, Monad m) => MultiStateT ss m a -> MultiStateT (s ': ss) m a
- inflateState :: (Monad m, ContainsType s ss) => StateT s m a -> MultiStateT ss m a
- inflateReader :: (Monad m, ContainsType r ss) => ReaderT r m a -> MultiStateT ss m a
- inflateWriter :: (Monad m, ContainsType w ss, Monoid w) => WriterT w m a -> MultiStateT ss m a
- mapMultiStateT :: (m (a, HList w) -> m' (a', HList w)) -> MultiStateT w m a -> MultiStateT w m' a'
- mGetRaw :: Monad m => MultiStateT a m (HList a)
- mPutRaw :: Monad m => HList s -> MultiStateT s m ()

# MultiStateT

newtype MultiStateT x m a Source #

A State transformer monad patameterized by:

- x - The list of types constituting the state,
- m - The inner monad.

`MultiStateT` corresponds to mtl's `StateT`, but can contain a heterogenous list of types.

This heterogenous list is represented using Types.Data.List, i.e:

- `'[]` - The empty list,
- `a ': b` - A list where `a` is an arbitrary type and `b` is the rest list.

For example,

    MultiStateT '[Int, Bool] :: (* -> *) -> (* -> *)

is a State wrapper containing the types [Int, Bool].

Constructors

MultiStateT |

Fields

- runMultiStateTRaw :: StateT (HList x) m a

#### Instances

Instances details

MonadBase b m => MonadBase b (MultiStateT s m) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy Methods liftBase :: b α -> MultiStateT s m α Source #
MonadBaseControl b m => MonadBaseControl b (MultiStateT s m) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy Associated Types type StM (MultiStateT s m) a Source # Methods liftBaseWith :: (RunInBase (MultiStateT s m) b -> b a) -> MultiStateT s m a Source # restoreM :: StM (MultiStateT s m) a -> MultiStateT s m a Source #
(Monad m, ContainsType a c) => MonadMultiGet a (MultiStateT c m) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy Methods mGet :: MultiStateT c m a Source #
(Monad m, ContainsType a c) => MonadMultiState a (MultiStateT c m) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy Methods mSet :: a -> MultiStateT c m () Source #
MonadState s m => MonadState s (MultiStateT c m) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy Methods get :: MultiStateT c m s put :: s -> MultiStateT c m () state :: (s -> (a, s)) -> MultiStateT c m a
MonadWriter w m => MonadWriter w (MultiStateT c m) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy Methods writer :: (a, w) -> MultiStateT c m a tell :: w -> MultiStateT c m () listen :: MultiStateT c m a -> MultiStateT c m (a, w) pass :: MultiStateT c m (a, w -> w) -> MultiStateT c m a
MonadTrans (MultiStateT x) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy Methods lift :: Monad m => m a -> MultiStateT x m a
MonadTransControl (MultiStateT s) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy Associated Types type StT (MultiStateT s) a Source # Methods liftWith :: Monad m => (Run (MultiStateT s) -> m a) -> MultiStateT s m a Source # restoreT :: Monad m => m (StT (MultiStateT s) a) -> MultiStateT s m a Source #
Monad m => Monad (MultiStateT x m) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy Methods (>>=) :: MultiStateT x m a -> (a -> MultiStateT x m b) -> MultiStateT x m b (>>) :: MultiStateT x m a -> MultiStateT x m b -> MultiStateT x m b return :: a -> MultiStateT x m a
Functor f => Functor (MultiStateT x f) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy Methods fmap :: (a -> b) -> MultiStateT x f a -> MultiStateT x f b (<$) :: a -> MultiStateT x f b -> MultiStateT x f a
MonadFix m => MonadFix (MultiStateT s m) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy Methods mfix :: (a -> MultiStateT s m a) -> MultiStateT s m a
(Applicative m, Monad m) => Applicative (MultiStateT x m) Source # |

Instance details

Defined in Control.Monad.Trans.MultiState.Lazy

Methods

pure :: a -> MultiStateT x m a

(<*>) :: MultiStateT x m (a -> b) -> MultiStateT x m a -> MultiStateT x m b

liftA2 :: (a -> b -> c) -> MultiStateT x m a -> MultiStateT x m b -> MultiStateT x m c

(*>) :: MultiStateT x m a -> MultiStateT x m b -> MultiStateT x m b

(<*) :: MultiStateT x m a -> MultiStateT x m b -> MultiStateT x m a

(Functor m, Applicative m, MonadPlus m) => Alternative (MultiStateT s m) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy Methods empty :: MultiStateT s m a (<|>) :: MultiStateT s m a -> MultiStateT s m a -> MultiStateT s m a some :: MultiStateT s m a -> MultiStateT s m [a] many :: MultiStateT s m a -> MultiStateT s m [a]
MonadPlus m => MonadPlus (MultiStateT s m) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy Methods mzero :: MultiStateT s m a mplus :: MultiStateT s m a -> MultiStateT s m a -> MultiStateT s m a
MonadIO m => MonadIO (MultiStateT c m) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy Methods liftIO :: IO a -> MultiStateT c m a
type StT (MultiStateT s) a Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy type StT (MultiStateT s) a = (a, HList s)
type StM (MultiStateT s m) a Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy type StM (MultiStateT s m) a = ComposeSt (MultiStateT s) m a

type MultiStateTNull = MultiStateT '[] Source #

A MultiState transformer carrying an empty state.

type MultiState x = MultiStateT x Identity Source #

A state monad parameterized by the list of types x of the state to carry.

Similar to `State s = StateT s Identity`

# MonadMultiState class

class Monad m => MonadMultiGet a m where Source #

In contrast to MonadMultiReader, MonadMultiGet is defined for State too, so it corresponds to read-access of any kind.

Note however that for MultiRWS, only the values from the `state` part can be accessed via `MonadMultiGet`, due to limitations of the design of `MultiRWS` and of the type system. This is issue is resolved in the `MultiGST` type.

Methods

mGet Source #

Arguments

:: m a | Access to a specific type in the environment.

#### Instances

Instances details

(MonadTrans t, Monad (t m), MonadMultiGet a m) => MonadMultiGet a (t m) Source # |
Instance details Defined in Control.Monad.Trans.MultiGet.Class Methods mGet :: t m a Source #
(Monad m, ContainsType a c) => MonadMultiGet a (MultiStateT c m) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Strict Methods mGet :: MultiStateT c m a Source #
(Monad m, ContainsType a c) => MonadMultiGet a (MultiStateT c m) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy Methods mGet :: MultiStateT c m a Source #
(Monad m, ContainsType a c) => MonadMultiGet a (MultiReaderT c m) Source # |
Instance details Defined in Control.Monad.Trans.MultiReader.Strict Methods mGet :: MultiReaderT c m a Source #
(Monad m, ContainsType a c) => MonadMultiGet a (MultiReaderT c m) Source # |
Instance details Defined in Control.Monad.Trans.MultiReader.Lazy Methods mGet :: MultiReaderT c m a Source #
(Monad m, HListMContains 'GettableFlag a cts) => MonadMultiGet a (MultiGSTT cts m) Source # |
Instance details Defined in Control.Monad.Trans.MultiGST.Strict Methods mGet :: MultiGSTT cts m a Source #
(Monad m, HListMContains 'GettableFlag a cts) => MonadMultiGet a (MultiGSTT cts m) Source # |
Instance details Defined in Control.Monad.Trans.MultiGST.Lazy Methods mGet :: MultiGSTT cts m a Source #
(Monad m, ContainsType a s) => MonadMultiGet a (MultiRWST r w s m) Source # |
Instance details Defined in Control.Monad.Trans.MultiRWS.Strict Methods mGet :: MultiRWST r w s m a Source #
(Monad m, ContainsType a s) => MonadMultiGet a (MultiRWST r w s m) Source # |
Instance details Defined in Control.Monad.Trans.MultiRWS.Lazy Methods mGet :: MultiRWST r w s m a Source #

class MonadMultiGet a m => MonadMultiState a m where Source #

Methods

mSet :: a -> m () Source #

#### Instances

Instances details

(MonadTrans t, Monad (t m), MonadMultiState a m) => MonadMultiState a (t m) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Class Methods mSet :: a -> t m () Source #
(Monad m, ContainsType a c) => MonadMultiState a (MultiStateT c m) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Strict Methods mSet :: a -> MultiStateT c m () Source #
(Monad m, ContainsType a c) => MonadMultiState a (MultiStateT c m) Source # |
Instance details Defined in Control.Monad.Trans.MultiState.Lazy Methods mSet :: a -> MultiStateT c m () Source #
(Monad m, HListMContains 'SettableFlag a cts) => MonadMultiState a (MultiGSTT cts m) Source # |
Instance details Defined in Control.Monad.Trans.MultiGST.Strict Methods mSet :: a -> MultiGSTT cts m () Source #
(Monad m, HListMContains 'SettableFlag a cts) => MonadMultiState a (MultiGSTT cts m) Source # |
Instance details Defined in Control.Monad.Trans.MultiGST.Lazy Methods mSet :: a -> MultiGSTT cts m () Source #
(Monad m, ContainsType a s) => MonadMultiState a (MultiRWST r w s m) Source # |
Instance details Defined in Control.Monad.Trans.MultiRWS.Strict Methods mSet :: a -> MultiRWST r w s m () Source #
(Monad m, ContainsType a s) => MonadMultiState a (MultiRWST r w s m) Source # |
Instance details Defined in Control.Monad.Trans.MultiRWS.Lazy Methods mSet :: a -> MultiRWST r w s m () Source #

# run-functions

runMultiStateT :: Functor m => HList s -> MultiStateT s m a -> m (a, HList s) Source #

runMultiStateTAS :: Functor m => HList s -> MultiStateT s m a -> m (a, HList s) Source #

runMultiStateTSA :: Monad m => HList s -> MultiStateT s m a -> m (HList s, a) Source #

runMultiStateTA :: Monad m => HList s -> MultiStateT s m a -> m a Source #

runMultiStateTS :: Monad m => HList s -> MultiStateT s m a -> m (HList s) Source #

runMultiStateT_ :: Functor m => HList s -> MultiStateT s m a -> m () Source #

runMultiStateTNil :: Monad m => MultiStateT '[] m a -> m a Source #

runMultiStateTNil_ :: Functor m => MultiStateT '[] m a -> m () Source #

# with-functions (single state)

withMultiState :: Monad m => s -> MultiStateT (s ': ss) m a -> MultiStateT ss m (a, s) Source #

withMultiStateAS :: Monad m => s -> MultiStateT (s ': ss) m a -> MultiStateT ss m (a, s) Source #

withMultiStateSA :: Monad m => s -> MultiStateT (s ': ss) m a -> MultiStateT ss m (s, a) Source #

withMultiStateA :: Monad m => s -> MultiStateT (s ': ss) m a -> MultiStateT ss m a Source #

withMultiStateS :: Monad m => s -> MultiStateT (s ': ss) m a -> MultiStateT ss m s Source #

withMultiState_ :: (Functor m, Monad m) => s -> MultiStateT (s ': ss) m a -> MultiStateT ss m () Source #

# with-functions (multiple states)

withMultiStates :: Monad m => HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (a, HList s1) Source #

withMultiStatesAS :: Monad m => HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (a, HList s1) Source #

withMultiStatesSA :: Monad m => HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (HList s1, a) Source #

withMultiStatesA :: Monad m => HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m a Source #

withMultiStatesS :: Monad m => HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (HList s1) Source #

withMultiStates_ :: (Functor m, Monad m) => HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m () Source #

# without-function (single state)

withoutMultiState :: (Functor m, Monad m) => MultiStateT ss m a -> MultiStateT (s ': ss) m a Source #

# inflate-functions (run single state in multiple states)

inflateState :: (Monad m, ContainsType s ss) => StateT s m a -> MultiStateT ss m a Source #

inflateReader :: (Monad m, ContainsType r ss) => ReaderT r m a -> MultiStateT ss m a Source #

inflateWriter :: (Monad m, ContainsType w ss, Monoid w) => WriterT w m a -> MultiStateT ss m a Source #

# other functions

mapMultiStateT :: (m (a, HList w) -> m' (a', HList w)) -> MultiStateT w m a -> MultiStateT w m' a' Source #

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

mGetRaw :: Monad m => MultiStateT a m (HList a) Source #

A raw extractor of the contained HList (i.e. the complete state).

mPutRaw :: Monad m => HList s -> MultiStateT s m () Source #