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

Safe HaskellSafe
LanguageHaskell2010

Control.Monad.Trans.MultiState.Lazy

Contents

Description

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

Synopsis

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

Instances

MonadBase b m => MonadBase b (MultiStateT s m) Source # 

Methods

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

MonadBaseControl b m => MonadBaseControl b (MultiStateT s m) Source # 

Associated Types

type StM (MultiStateT s m :: * -> *) a :: * #

Methods

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

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

MonadState s m => MonadState s (MultiStateT c m) Source # 

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 # 

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 #

(Monad m, ContainsType a c) => MonadMultiState a (MultiStateT c m) Source # 

Methods

mSet :: a -> MultiStateT c m () Source #

mGet :: MultiStateT c m a Source #

MonadTrans (MultiStateT x) Source # 

Methods

lift :: Monad m => m a -> MultiStateT x m a #

MonadTransControl (MultiStateT s) Source # 

Associated Types

type StT (MultiStateT s :: (* -> *) -> * -> *) a :: * #

Methods

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

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

Monad m => Monad (MultiStateT x m) Source # 

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 #

fail :: String -> MultiStateT x m a #

Functor f => Functor (MultiStateT x f) Source # 

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 # 

Methods

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

(Applicative m, Monad m) => Applicative (MultiStateT x m) Source # 

Methods

pure :: a -> MultiStateT x m a #

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

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

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

MonadIO m => MonadIO (MultiStateT c m) Source # 

Methods

liftIO :: IO a -> MultiStateT c m a #

(Functor m, Applicative m, MonadPlus m) => Alternative (MultiStateT s m) Source # 

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 # 

Methods

mzero :: MultiStateT s m a #

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

type StT (MultiStateT s) a Source # 
type StT (MultiStateT s) a = (a, HList s)
type StM (MultiStateT s m) a Source # 
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 => MonadMultiState a m where Source #

All methods must be defined.

The idea is: Any monad stack is instance of MonadMultiState a, iff the stack contains a MultiStateT x with a element of x.

Minimal complete definition

mSet, mGet

Methods

mSet :: a -> m () Source #

state set function for values of type a.

mGet :: m a Source #

state get function for values of type a.

Instances

(MonadTrans t, Monad (t m), MonadMultiState a m) => MonadMultiState a (t m) Source # 

Methods

mSet :: a -> t m () Source #

mGet :: t m a Source #

(Monad m, ContainsType a c) => MonadMultiState a (MultiStateT c m) Source # 

Methods

mSet :: a -> MultiStateT c m () Source #

mGet :: MultiStateT c m a Source #

(Monad m, ContainsType a c) => MonadMultiState a (MultiStateT c m) Source # 

Methods

mSet :: a -> MultiStateT c m () Source #

mGet :: MultiStateT c m a Source #

(Monad m, ContainsType a s) => MonadMultiState a (MultiRWST r w s m) Source # 

Methods

mSet :: a -> MultiRWST r w s m () Source #

mGet :: MultiRWST r w s m a Source #

(Monad m, ContainsType a s) => MonadMultiState a (MultiRWST r w s m) Source # 

Methods

mSet :: a -> MultiRWST r w s m () Source #

mGet :: MultiRWST r w s m a 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 #

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 #