    {-# LANGUAGE CPP #-}

    -- | The multi-valued version of mtl's State / StateT
    module Control.Monad.Trans.MultiState.Lazy
      (
      -- * MultiStateT
        MultiStateT(..)
      , MultiStateTNull
      , MultiState
      -- * MonadMultiState class
      , MonadMultiGet(..)
      , MonadMultiState(..)
      -- * run-functions
      , runMultiStateT
      , runMultiStateTAS
      , runMultiStateTSA
      , runMultiStateTA
      , runMultiStateTS
      , runMultiStateT_
      , runMultiStateTNil
      , runMultiStateTNil_
      -- * with-functions (single state)
      , withMultiState
      , withMultiStateAS
      , withMultiStateSA
      , withMultiStateA
      , withMultiStateS
      , withMultiState_
      -- * with-functions (multiple states)
      , withMultiStates
      , withMultiStatesAS
      , withMultiStatesSA
      , withMultiStatesA
      , withMultiStatesS
      , withMultiStates_
      -- * without-function (single state)
      , withoutMultiState
      -- * inflate-functions (run single state in multiple states)
      , inflateState
      , inflateReader
      , inflateWriter
      -- * other functions
      , mapMultiStateT
      , mGetRaw
      , mPutRaw
    ) where

    import Data.HList.HList
    import Data.HList.ContainsType

    import Control.Monad.Trans.MultiState.Class

    import Control.Monad.State.Lazy        ( StateT(..)
                                           , MonadState(..)
                                           , evalStateT
                                           , execStateT
                                           , mapStateT )
    import Control.Monad.Reader            ( ReaderT(..) )
    import Control.Monad.Writer.Lazy       ( WriterT(..) )
    import Control.Monad.Trans.Class       ( MonadTrans
                                           , lift )
    import Control.Monad.Writer.Class      ( MonadWriter
                                           , listen
                                           , tell
                                           , writer
                                           , pass )

    import Data.Functor.Identity           ( Identity )

    import Control.Applicative             ( Applicative(..)
                                           , Alternative(..)
                                           )
    import Control.Monad                   ( MonadPlus(..)
                                           , liftM
                                           , ap
                                           , void )
    import Control.Monad.Base              ( MonadBase(..)
                                           , liftBaseDefault
                                           )
    import Control.Monad.Trans.Control     ( MonadTransControl(..)
                                           , MonadBaseControl(..)
                                           , ComposeSt
                                           , defaultLiftBaseWith
                                           , defaultRestoreM
                                           )
    import Data.Monoid                     ( Monoid )
    import Control.Monad.Fix               ( MonadFix(..) )
    import Control.Monad.IO.Class          ( MonadIO(..) )

    -- | 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].
    newtype MultiStateT x m a = MultiStateT {
      forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw :: StateT (HList x) m a
    }

    -- | A MultiState transformer carrying an empty state.
    type MultiStateTNull = MultiStateT '[]

    -- | A state monad parameterized by the list of types x of the state to carry.
    --
    -- Similar to @State s = StateT s Identity@
    type MultiState x = MultiStateT x Identity

    -- some instances

    instance (Functor f) => Functor (MultiStateT x f) where
      fmap :: forall a b. (a -> b) -> MultiStateT x f a -> MultiStateT x f b
    fmap a -> b
    f = StateT (HList x) f b -> MultiStateT x f b
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList x) f b -> MultiStateT x f b)
    -> (MultiStateT x f a -> StateT (HList x) f b)
    -> MultiStateT x f a
    -> MultiStateT x f b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (a -> b) -> StateT (HList x) f a -> StateT (HList x) f b
    forall a b.
    (a -> b) -> StateT (HList x) f a -> StateT (HList x) f b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap a -> b
    f (StateT (HList x) f a -> StateT (HList x) f b)
    -> (MultiStateT x f a -> StateT (HList x) f a)
    -> MultiStateT x f a
    -> StateT (HList x) f b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MultiStateT x f a -> StateT (HList x) f a
    forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw

    instance (Applicative m, Monad m) => Applicative (MultiStateT x m) where
      pure :: forall a. a -> MultiStateT x m a
    pure = StateT (HList x) m a -> MultiStateT x m a
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList x) m a -> MultiStateT x m a)
    -> (a -> StateT (HList x) m a) -> a -> MultiStateT x m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> StateT (HList x) m a
    forall a. a -> StateT (HList x) m a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure
      <*> :: forall a b.
    MultiStateT x m (a -> b) -> MultiStateT x m a -> MultiStateT x m b
    (<*>) = MultiStateT x m (a -> b) -> MultiStateT x m a -> MultiStateT x m b
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    ap

    instance Monad m => Monad (MultiStateT x m) where
      return :: forall a. a -> MultiStateT x m a
    return = a -> MultiStateT x m a
    forall a. a -> MultiStateT x m a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure
      MultiStateT x m a
    k >>= :: forall a b.
    MultiStateT x m a -> (a -> MultiStateT x m b) -> MultiStateT x m b
    >>= a -> MultiStateT x m b
    f = StateT (HList x) m b -> MultiStateT x m b
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList x) m b -> MultiStateT x m b)
    -> StateT (HList x) m b -> MultiStateT x m b
    forall a b. (a -> b) -> a -> b
    $ MultiStateT x m a -> StateT (HList x) m a
    forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw MultiStateT x m a
    k StateT (HList x) m a
    -> (a -> StateT (HList x) m b) -> StateT (HList x) m b
    forall a b.
    StateT (HList x) m a
    -> (a -> StateT (HList x) m b) -> StateT (HList x) m b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= (MultiStateT x m b -> StateT (HList x) m b
    forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw(MultiStateT x m b -> StateT (HList x) m b)
    -> (a -> MultiStateT x m b) -> a -> StateT (HList x) m b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .a -> MultiStateT x m b
    f)

    instance MonadTrans (MultiStateT x) where
      lift :: forall (m :: * -> *) a. Monad m => m a -> MultiStateT x m a
    lift = StateT (HList x) m a -> MultiStateT x m a
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList x) m a -> MultiStateT x m a)
    -> (m a -> StateT (HList x) m a) -> m a -> MultiStateT x m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . m a -> StateT (HList x) m a
    forall (m :: * -> *) a. Monad m => m a -> StateT (HList x) m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift

    #if MIN_VERSION_base(4,8,0)
    instance {-# OVERLAPPING #-} (Monad m, ContainsType a c)
    #else
    instance (Monad m, ContainsType a c)
    #endif
          => MonadMultiGet a (MultiStateT c m) where
      mGet :: MultiStateT c m a
    mGet = StateT (HList c) m a -> MultiStateT c m a
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList c) m a -> MultiStateT c m a)
    -> StateT (HList c) m a -> MultiStateT c m a
    forall a b. (a -> b) -> a -> b
    $ (HList c -> a)
    -> StateT (HList c) m (HList c) -> StateT (HList c) m a
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM HList c -> a
    forall a (c :: [*]). ContainsType a c => HList c -> a
    getHListElem StateT (HList c) m (HList c)
    forall s (m :: * -> *). MonadState s m => m s
    get

    #if MIN_VERSION_base(4,8,0)
    instance {-# OVERLAPPING #-} (Monad m, ContainsType a c)
    #else
    instance (Monad m, ContainsType a c)
    #endif
          => MonadMultiState a (MultiStateT c m) where
      mSet :: a -> MultiStateT c m ()
    mSet a
    v = StateT (HList c) m () -> MultiStateT c m ()
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList c) m () -> MultiStateT c m ())
    -> StateT (HList c) m () -> MultiStateT c m ()
    forall a b. (a -> b) -> a -> b
    $ StateT (HList c) m (HList c)
    forall s (m :: * -> *). MonadState s m => m s
    get StateT (HList c) m (HList c)
    -> (HList c -> StateT (HList c) m ()) -> StateT (HList c) m ()
    forall a b.
    StateT (HList c) m a
    -> (a -> StateT (HList c) m b) -> StateT (HList c) m b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= HList c -> StateT (HList c) m ()
    forall s (m :: * -> *). MonadState s m => s -> m ()
    put (HList c -> StateT (HList c) m ())
    -> (HList c -> HList c) -> HList c -> StateT (HList c) m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> HList c -> HList c
    forall a (c :: [*]). ContainsType a c => a -> HList c -> HList c
    setHListElem a
    v

    instance MonadFix m => MonadFix (MultiStateT s m) where
      mfix :: forall a. (a -> MultiStateT s m a) -> MultiStateT s m a
    mfix a -> MultiStateT s m a
    f = StateT (HList s) m a -> MultiStateT s m a
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList s) m a -> MultiStateT s m a)
    -> StateT (HList s) m a -> MultiStateT s m a
    forall a b. (a -> b) -> a -> b
    $ (a -> StateT (HList s) m a) -> StateT (HList s) m a
    forall a. (a -> StateT (HList s) m a) -> StateT (HList s) m a
    forall (m :: * -> *) a. MonadFix m => (a -> m a) -> m a
    mfix (MultiStateT s m a -> StateT (HList s) m a
    forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw (MultiStateT s m a -> StateT (HList s) m a)
    -> (a -> MultiStateT s m a) -> a -> StateT (HList s) m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> MultiStateT s m a
    f)

    -- methods

    -- | A raw extractor of the contained HList (i.e. the complete state).
    mGetRaw :: Monad m => MultiStateT a m (HList a)
    mGetRaw :: forall (m :: * -> *) (a :: [*]).
    Monad m =>
    MultiStateT a m (HList a)
    mGetRaw = StateT (HList a) m (HList a) -> MultiStateT a m (HList a)
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT StateT (HList a) m (HList a)
    forall s (m :: * -> *). MonadState s m => m s
    get

    mPutRaw :: Monad m => HList s -> MultiStateT s m ()
    mPutRaw :: forall (m :: * -> *) (s :: [*]).
    Monad m =>
    HList s -> MultiStateT s m ()
    mPutRaw = StateT (HList s) m () -> MultiStateT s m ()
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList s) m () -> MultiStateT s m ())
    -> (HList s -> StateT (HList s) m ())
    -> HList s
    -> MultiStateT s m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . HList s -> StateT (HList s) m ()
    forall s (m :: * -> *). MonadState s m => s -> m ()
    put

    -- | Map both the return value and the state of a computation
    -- using the given function.
    mapMultiStateT :: (m (a, HList w) -> m' (a', HList w))
                   -> MultiStateT w m  a
                   -> MultiStateT w m' a'
    mapMultiStateT :: forall (m :: * -> *) a (w :: [*]) (m' :: * -> *) a'.
    (m (a, HList w) -> m' (a', HList w))
    -> MultiStateT w m a -> MultiStateT w m' a'
    mapMultiStateT m (a, HList w) -> m' (a', HList w)
    f = StateT (HList w) m' a' -> MultiStateT w m' a'
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList w) m' a' -> MultiStateT w m' a')
    -> (MultiStateT w m a -> StateT (HList w) m' a')
    -> MultiStateT w m a
    -> MultiStateT w m' a'
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (m (a, HList w) -> m' (a', HList w))
    -> StateT (HList w) m a -> StateT (HList w) m' a'
    forall (m :: * -> *) a s (n :: * -> *) b.
    (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
    mapStateT m (a, HList w) -> m' (a', HList w)
    f (StateT (HList w) m a -> StateT (HList w) m' a')
    -> (MultiStateT w m a -> StateT (HList w) m a)
    -> MultiStateT w m a
    -> StateT (HList w) m' a'
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MultiStateT w m a -> StateT (HList w) m a
    forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw

    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 ()
    -- ghc too dumb for this shortcut, unfortunately
    -- runMultiStateT   s k = runMultiStateTNil $ withMultiStates s k
    -- runMultiStateTAS s k = runMultiStateTNil $ withMultiStatesAS s k
    -- runMultiStateTSA s k = runMultiStateTNil $ withMultiStatesSA s k
    -- runMultiStateTA  s k = runMultiStateTNil $ withMultiStatesA s k
    -- runMultiStateTS  s k = runMultiStateTNil $ withMultiStatesS s k
    -- runMultiStateT_  s k = runMultiStateTNil $ withMultiStates_ s k
    runMultiStateT :: forall (m :: * -> *) (s :: [*]) a.
    Functor m =>
    HList s -> MultiStateT s m a -> m (a, HList s)
    runMultiStateT   HList s
    s MultiStateT s m a
    k = HList s -> MultiStateT s m a -> m (a, HList s)
    forall (m :: * -> *) (s :: [*]) a.
    Functor m =>
    HList s -> MultiStateT s m a -> m (a, HList s)
    runMultiStateTAS HList s
    s MultiStateT s m a
    k
    runMultiStateTAS :: forall (m :: * -> *) (s :: [*]) a.
    Functor m =>
    HList s -> MultiStateT s m a -> m (a, HList s)
    runMultiStateTAS HList s
    s MultiStateT s m a
    k = StateT (HList s) m a -> HList s -> m (a, HList s)
    forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
    runStateT (MultiStateT s m a -> StateT (HList s) m a
    forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw MultiStateT s m a
    k) HList s
    s
    runMultiStateTSA :: forall (m :: * -> *) (s :: [*]) a.
    Monad m =>
    HList s -> MultiStateT s m a -> m (HList s, a)
    runMultiStateTSA HList s
    s MultiStateT s m a
    k = (\(~(a
    a,HList s
    b)) -> (HList s
    b,a
    a)) ((a, HList s) -> (HList s, a)) -> m (a, HList s) -> m (HList s, a)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    `liftM` StateT (HList s) m a -> HList s -> m (a, HList s)
    forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
    runStateT (MultiStateT s m a -> StateT (HList s) m a
    forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw MultiStateT s m a
    k) HList s
    s
    runMultiStateTA :: forall (m :: * -> *) (s :: [*]) a.
    Monad m =>
    HList s -> MultiStateT s m a -> m a
    runMultiStateTA  HList s
    s MultiStateT s m a
    k = StateT (HList s) m a -> HList s -> m a
    forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
    evalStateT (MultiStateT s m a -> StateT (HList s) m a
    forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw MultiStateT s m a
    k) HList s
    s
    runMultiStateTS :: forall (m :: * -> *) (s :: [*]) a.
    Monad m =>
    HList s -> MultiStateT s m a -> m (HList s)
    runMultiStateTS  HList s
    s MultiStateT s m a
    k = StateT (HList s) m a -> HList s -> m (HList s)
    forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m s
    execStateT (MultiStateT s m a -> StateT (HList s) m a
    forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw MultiStateT s m a
    k) HList s
    s
    runMultiStateT_ :: forall (m :: * -> *) (s :: [*]) a.
    Functor m =>
    HList s -> MultiStateT s m a -> m ()
    runMultiStateT_  HList s
    s MultiStateT s m a
    k = m (a, HList s) -> m ()
    forall (f :: * -> *) a. Functor f => f a -> f ()
    void (m (a, HList s) -> m ()) -> m (a, HList s) -> m ()
    forall a b. (a -> b) -> a -> b
    $ StateT (HList s) m a -> HList s -> m (a, HList s)
    forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
    runStateT (MultiStateT s m a -> StateT (HList s) m a
    forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw MultiStateT s m a
    k) HList s
    s

    runMultiStateTNil  ::   Monad m => MultiStateT '[] m a -> m a
    runMultiStateTNil_ :: Functor m => MultiStateT '[] m a -> m ()
    runMultiStateTNil :: forall (m :: * -> *) a. Monad m => MultiStateT '[] m a -> m a
    runMultiStateTNil  MultiStateT '[] m a
    k = StateT (HList '[]) m a -> HList '[] -> m a
    forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
    evalStateT (MultiStateT '[] m a -> StateT (HList '[]) m a
    forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw MultiStateT '[] m a
    k) HList '[]
    HNil
    runMultiStateTNil_ :: forall (m :: * -> *) a. Functor m => MultiStateT '[] m a -> m ()
    runMultiStateTNil_ MultiStateT '[] m a
    k = m (a, HList '[]) -> m ()
    forall (f :: * -> *) a. Functor f => f a -> f ()
    void (m (a, HList '[]) -> m ()) -> m (a, HList '[]) -> m ()
    forall a b. (a -> b) -> a -> b
    $ StateT (HList '[]) m a -> HList '[] -> m (a, HList '[])
    forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
    runStateT (MultiStateT '[] m a -> StateT (HList '[]) m a
    forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw MultiStateT '[] m a
    k) HList '[]
    HNil

    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 ()
    withMultiState :: forall (m :: * -> *) s (ss :: [*]) a.
    Monad m =>
    s -> MultiStateT (s : ss) m a -> MultiStateT ss m (a, s)
    withMultiState = s -> MultiStateT (s : ss) m a -> MultiStateT ss m (a, s)
    forall (m :: * -> *) s (ss :: [*]) a.
    Monad m =>
    s -> MultiStateT (s : ss) m a -> MultiStateT ss m (a, s)
    withMultiStateAS
    withMultiStateAS :: forall (m :: * -> *) s (ss :: [*]) a.
    Monad m =>
    s -> MultiStateT (s : ss) m a -> MultiStateT ss m (a, s)
    withMultiStateAS s
    x MultiStateT (s : ss) m a
    k = StateT (HList ss) m (a, s) -> MultiStateT ss m (a, s)
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList ss) m (a, s) -> MultiStateT ss m (a, s))
    -> StateT (HList ss) m (a, s) -> MultiStateT ss m (a, s)
    forall a b. (a -> b) -> a -> b
    $ do
      HList ss
    s <- StateT (HList ss) m (HList ss)
    forall s (m :: * -> *). MonadState s m => m s
    get
      ~(a
    a, HList (s : ss)
    s') <- m (a, HList (s : ss)) -> StateT (HList ss) m (a, HList (s : ss))
    forall (m :: * -> *) a. Monad m => m a -> StateT (HList ss) m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m (a, HList (s : ss)) -> StateT (HList ss) m (a, HList (s : ss)))
    -> m (a, HList (s : ss)) -> StateT (HList ss) m (a, HList (s : ss))
    forall a b. (a -> b) -> a -> b
    $ StateT (HList (s : ss)) m a
    -> HList (s : ss) -> m (a, HList (s : ss))
    forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
    runStateT (MultiStateT (s : ss) m a -> StateT (HList (s : ss)) m a
    forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw MultiStateT (s : ss) m a
    k) (s
    x s -> HList ss -> HList (s : ss)
    forall x (xs :: [*]). x -> HList xs -> HList (x : xs)
    :+: HList ss
    s)
      case HList (s : ss)
    s' of x
    x' :+: HList xs
    sr' -> do HList xs -> StateT (HList ss) m ()
    forall s (m :: * -> *). MonadState s m => s -> m ()
    put HList xs
    sr'; (a, s) -> StateT (HList ss) m (a, s)
    forall a. a -> StateT (HList ss) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (a
    a, s
    x
    x')
    withMultiStateSA :: forall (m :: * -> *) s (ss :: [*]) a.
    Monad m =>
    s -> MultiStateT (s : ss) m a -> MultiStateT ss m (s, a)
    withMultiStateSA s
    s MultiStateT (s : ss) m a
    k = (\(~(a
    a,s
    b)) -> (s
    b,a
    a)) ((a, s) -> (s, a))
    -> MultiStateT ss m (a, s) -> MultiStateT ss m (s, a)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    `liftM` s -> MultiStateT (s : ss) m a -> MultiStateT ss m (a, s)
    forall (m :: * -> *) s (ss :: [*]) a.
    Monad m =>
    s -> MultiStateT (s : ss) m a -> MultiStateT ss m (a, s)
    withMultiStateAS s
    s MultiStateT (s : ss) m a
    k
    withMultiStateA :: forall (m :: * -> *) s (ss :: [*]) a.
    Monad m =>
    s -> MultiStateT (s : ss) m a -> MultiStateT ss m a
    withMultiStateA  s
    s MultiStateT (s : ss) m a
    k = (a, s) -> a
    forall a b. (a, b) -> a
    fst ((a, s) -> a) -> MultiStateT ss m (a, s) -> MultiStateT ss m a
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    `liftM` s -> MultiStateT (s : ss) m a -> MultiStateT ss m (a, s)
    forall (m :: * -> *) s (ss :: [*]) a.
    Monad m =>
    s -> MultiStateT (s : ss) m a -> MultiStateT ss m (a, s)
    withMultiStateAS s
    s MultiStateT (s : ss) m a
    k
    withMultiStateS :: forall (m :: * -> *) s (ss :: [*]) a.
    Monad m =>
    s -> MultiStateT (s : ss) m a -> MultiStateT ss m s
    withMultiStateS  s
    s MultiStateT (s : ss) m a
    k = (a, s) -> s
    forall a b. (a, b) -> b
    snd ((a, s) -> s) -> MultiStateT ss m (a, s) -> MultiStateT ss m s
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    `liftM` s -> MultiStateT (s : ss) m a -> MultiStateT ss m (a, s)
    forall (m :: * -> *) s (ss :: [*]) a.
    Monad m =>
    s -> MultiStateT (s : ss) m a -> MultiStateT ss m (a, s)
    withMultiStateAS s
    s MultiStateT (s : ss) m a
    k
    withMultiState_ :: forall (m :: * -> *) s (ss :: [*]) a.
    (Functor m, Monad m) =>
    s -> MultiStateT (s : ss) m a -> MultiStateT ss m ()
    withMultiState_  s
    s MultiStateT (s : ss) m a
    k = MultiStateT ss m (a, s) -> MultiStateT ss m ()
    forall (f :: * -> *) a. Functor f => f a -> f ()
    void (MultiStateT ss m (a, s) -> MultiStateT ss m ())
    -> MultiStateT ss m (a, s) -> MultiStateT ss m ()
    forall a b. (a -> b) -> a -> b
    $ s -> MultiStateT (s : ss) m a -> MultiStateT ss m (a, s)
    forall (m :: * -> *) s (ss :: [*]) a.
    Monad m =>
    s -> MultiStateT (s : ss) m a -> MultiStateT ss m (a, s)
    withMultiStateAS s
    s MultiStateT (s : ss) m a
    k

    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 ()
    withMultiStates :: forall (m :: * -> *) (s1 :: [*]) (s2 :: [*]) a.
    Monad m =>
    HList s1
    -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (a, HList s1)
    withMultiStates = HList s1
    -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (a, HList s1)
    forall (m :: * -> *) (s1 :: [*]) (s2 :: [*]) a.
    Monad m =>
    HList s1
    -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (a, HList s1)
    withMultiStatesAS
    withMultiStatesAS :: forall (m :: * -> *) (s1 :: [*]) (s2 :: [*]) a.
    Monad m =>
    HList s1
    -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (a, HList s1)
    withMultiStatesAS HList s1
    HNil       = (a -> (a, HList s1))
    -> MultiStateT s2 m a -> MultiStateT s2 m (a, HList s1)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM (\a
    r -> (a
    r, HList s1
    HList '[]
    HNil))
    withMultiStatesAS (x
    x :+: HList xs
    xs) = (((a, x), HList xs) -> (a, HList s1))
    -> MultiStateT s2 m ((a, x), HList xs)
    -> MultiStateT s2 m (a, HList s1)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM (\(~(~(a
    a, x
    x'), HList xs
    xs')) -> (a
    a, x
    x' x -> HList xs -> HList (x : xs)
    forall x (xs :: [*]). x -> HList xs -> HList (x : xs)
    :+: HList xs
    xs'))
                            (MultiStateT s2 m ((a, x), HList xs)
     -> MultiStateT s2 m (a, HList s1))
    -> (MultiStateT (x : Append xs s2) m a
        -> MultiStateT s2 m ((a, x), HList xs))
    -> MultiStateT (x : Append xs s2) m a
    -> MultiStateT s2 m (a, HList s1)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . HList xs
    -> MultiStateT (Append xs s2) m (a, x)
    -> MultiStateT s2 m ((a, x), HList xs)
    forall (m :: * -> *) (s1 :: [*]) (s2 :: [*]) a.
    Monad m =>
    HList s1
    -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (a, HList s1)
    withMultiStatesAS HList xs
    xs
                            (MultiStateT (Append xs s2) m (a, x)
     -> MultiStateT s2 m ((a, x), HList xs))
    -> (MultiStateT (x : Append xs s2) m a
        -> MultiStateT (Append xs s2) m (a, x))
    -> MultiStateT (x : Append xs s2) m a
    -> MultiStateT s2 m ((a, x), HList xs)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . x
    -> MultiStateT (x : Append xs s2) m a
    -> MultiStateT (Append xs s2) m (a, x)
    forall (m :: * -> *) s (ss :: [*]) a.
    Monad m =>
    s -> MultiStateT (s : ss) m a -> MultiStateT ss m (a, s)
    withMultiStateAS x
    x
    withMultiStatesSA :: forall (m :: * -> *) (s1 :: [*]) (s2 :: [*]) a.
    Monad m =>
    HList s1
    -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (HList s1, a)
    withMultiStatesSA HList s1
    HNil       = (a -> (HList s1, a))
    -> MultiStateT s2 m a -> MultiStateT s2 m (HList s1, a)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM (\a
    r -> (HList s1
    HList '[]
    HNil, a
    r))
    withMultiStatesSA (x
    x :+: HList xs
    xs) = (((a, x), HList xs) -> (HList s1, a))
    -> MultiStateT s2 m ((a, x), HList xs)
    -> MultiStateT s2 m (HList s1, a)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM (\(~(~(a
    a, x
    x'), HList xs
    xs')) -> (x
    x' x -> HList xs -> HList (x : xs)
    forall x (xs :: [*]). x -> HList xs -> HList (x : xs)
    :+: HList xs
    xs', a
    a))
                            (MultiStateT s2 m ((a, x), HList xs)
     -> MultiStateT s2 m (HList s1, a))
    -> (MultiStateT (x : Append xs s2) m a
        -> MultiStateT s2 m ((a, x), HList xs))
    -> MultiStateT (x : Append xs s2) m a
    -> MultiStateT s2 m (HList s1, a)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . HList xs
    -> MultiStateT (Append xs s2) m (a, x)
    -> MultiStateT s2 m ((a, x), HList xs)
    forall (m :: * -> *) (s1 :: [*]) (s2 :: [*]) a.
    Monad m =>
    HList s1
    -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (a, HList s1)
    withMultiStatesAS HList xs
    xs
                            (MultiStateT (Append xs s2) m (a, x)
     -> MultiStateT s2 m ((a, x), HList xs))
    -> (MultiStateT (x : Append xs s2) m a
        -> MultiStateT (Append xs s2) m (a, x))
    -> MultiStateT (x : Append xs s2) m a
    -> MultiStateT s2 m ((a, x), HList xs)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . x
    -> MultiStateT (x : Append xs s2) m a
    -> MultiStateT (Append xs s2) m (a, x)
    forall (m :: * -> *) s (ss :: [*]) a.
    Monad m =>
    s -> MultiStateT (s : ss) m a -> MultiStateT ss m (a, s)
    withMultiStateAS x
    x
    withMultiStatesA :: forall (m :: * -> *) (s1 :: [*]) (s2 :: [*]) a.
    Monad m =>
    HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m a
    withMultiStatesA  HList s1
    HNil       = MultiStateT s2 m a -> MultiStateT s2 m a
    MultiStateT (Append s1 s2) m a -> MultiStateT s2 m a
    forall a. a -> a
    id
    withMultiStatesA  (x
    x :+: HList xs
    xs) = HList xs -> MultiStateT (Append xs s2) m a -> MultiStateT s2 m a
    forall (m :: * -> *) (s1 :: [*]) (s2 :: [*]) a.
    Monad m =>
    HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m a
    withMultiStatesA HList xs
    xs (MultiStateT (Append xs s2) m a -> MultiStateT s2 m a)
    -> (MultiStateT (x : Append xs s2) m a
        -> MultiStateT (Append xs s2) m a)
    -> MultiStateT (x : Append xs s2) m a
    -> MultiStateT s2 m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . x
    -> MultiStateT (x : Append xs s2) m a
    -> MultiStateT (Append xs s2) m a
    forall (m :: * -> *) s (ss :: [*]) a.
    Monad m =>
    s -> MultiStateT (s : ss) m a -> MultiStateT ss m a
    withMultiStateA x
    x
    withMultiStatesS :: forall (m :: * -> *) (s1 :: [*]) (s2 :: [*]) a.
    Monad m =>
    HList s1
    -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (HList s1)
    withMultiStatesS  HList s1
    HNil       = (a -> HList s1)
    -> MultiStateT s2 m a -> MultiStateT s2 m (HList s1)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM (HList s1 -> a -> HList s1
    forall a b. a -> b -> a
    const HList s1
    HList '[]
    HNil)
    withMultiStatesS (x
    x :+: HList xs
    xs)  = ((x, HList xs) -> HList s1)
    -> MultiStateT s2 m (x, HList xs) -> MultiStateT s2 m (HList s1)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM (\(~(x
    x', HList xs
    xs')) -> x
    x' x -> HList xs -> HList (x : xs)
    forall x (xs :: [*]). x -> HList xs -> HList (x : xs)
    :+: HList xs
    xs')
                            (MultiStateT s2 m (x, HList xs) -> MultiStateT s2 m (HList s1))
    -> (MultiStateT (x : Append xs s2) m a
        -> MultiStateT s2 m (x, HList xs))
    -> MultiStateT (x : Append xs s2) m a
    -> MultiStateT s2 m (HList s1)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . HList xs
    -> MultiStateT (Append xs s2) m x -> MultiStateT s2 m (x, HList xs)
    forall (m :: * -> *) (s1 :: [*]) (s2 :: [*]) a.
    Monad m =>
    HList s1
    -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (a, HList s1)
    withMultiStatesAS HList xs
    xs
                            (MultiStateT (Append xs s2) m x -> MultiStateT s2 m (x, HList xs))
    -> (MultiStateT (x : Append xs s2) m a
        -> MultiStateT (Append xs s2) m x)
    -> MultiStateT (x : Append xs s2) m a
    -> MultiStateT s2 m (x, HList xs)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . x
    -> MultiStateT (x : Append xs s2) m a
    -> MultiStateT (Append xs s2) m x
    forall (m :: * -> *) s (ss :: [*]) a.
    Monad m =>
    s -> MultiStateT (s : ss) m a -> MultiStateT ss m s
    withMultiStateS x
    x
    withMultiStates_ :: forall (m :: * -> *) (s1 :: [*]) (s2 :: [*]) a.
    (Functor m, Monad m) =>
    HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m ()
    withMultiStates_  HList s1
    HNil       = (a -> ()) -> MultiStateT s2 m a -> MultiStateT s2 m ()
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM (() -> a -> ()
    forall a b. a -> b -> a
    const ())
    withMultiStates_ (x
    x :+: HList xs
    xs)  = HList xs -> MultiStateT (Append xs s2) m () -> MultiStateT s2 m ()
    forall (m :: * -> *) (s1 :: [*]) (s2 :: [*]) a.
    (Functor m, Monad m) =>
    HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m ()
    withMultiStates_ HList xs
    xs (MultiStateT (Append xs s2) m () -> MultiStateT s2 m ())
    -> (MultiStateT (x : Append xs s2) m a
        -> MultiStateT (Append xs s2) m ())
    -> MultiStateT (x : Append xs s2) m a
    -> MultiStateT s2 m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . x
    -> MultiStateT (x : Append xs s2) m a
    -> MultiStateT (Append xs s2) m ()
    forall (m :: * -> *) s (ss :: [*]) a.
    (Functor m, Monad m) =>
    s -> MultiStateT (s : ss) m a -> MultiStateT ss m ()
    withMultiState_ x
    x

    withoutMultiState :: (Functor m, Monad m) => MultiStateT ss m a -> MultiStateT (s ': ss) m a
    withoutMultiState :: forall (m :: * -> *) (ss :: [*]) a s.
    (Functor m, Monad m) =>
    MultiStateT ss m a -> MultiStateT (s : ss) m a
    withoutMultiState MultiStateT ss m a
    k = StateT (HList (s : ss)) m a -> MultiStateT (s : ss) m a
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList (s : ss)) m a -> MultiStateT (s : ss) m a)
    -> StateT (HList (s : ss)) m a -> MultiStateT (s : ss) m a
    forall a b. (a -> b) -> a -> b
    $ StateT (HList (s : ss)) m (HList (s : ss))
    forall s (m :: * -> *). MonadState s m => m s
    get StateT (HList (s : ss)) m (HList (s : ss))
    -> (HList (s : ss) -> StateT (HList (s : ss)) m a)
    -> StateT (HList (s : ss)) m a
    forall a b.
    StateT (HList (s : ss)) m a
    -> (a -> StateT (HList (s : ss)) m b)
    -> StateT (HList (s : ss)) m b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \case
      x
    s :+: HList xs
    sr -> do
        ~(a
    a, HList xs
    sr') <- m (a, HList xs) -> StateT (HList (s : ss)) m (a, HList xs)
    forall (m :: * -> *) a.
    Monad m =>
    m a -> StateT (HList (s : ss)) m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m (a, HList xs) -> StateT (HList (s : ss)) m (a, HList xs))
    -> m (a, HList xs) -> StateT (HList (s : ss)) m (a, HList xs)
    forall a b. (a -> b) -> a -> b
    $ HList xs -> MultiStateT xs m a -> m (a, HList xs)
    forall (m :: * -> *) (s :: [*]) a.
    Functor m =>
    HList s -> MultiStateT s m a -> m (a, HList s)
    runMultiStateT HList xs
    sr MultiStateT ss m a
    MultiStateT xs m a
    k
        HList (x : xs) -> StateT (HList (s : ss)) m ()
    forall s (m :: * -> *). MonadState s m => s -> m ()
    put (x
    s x -> HList xs -> HList (x : xs)
    forall x (xs :: [*]). x -> HList xs -> HList (x : xs)
    :+: HList xs
    sr')
        a -> StateT (HList (s : ss)) m a
    forall a. a -> StateT (HList (s : ss)) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return a
    a

    inflateState :: (Monad m, ContainsType s ss)
                 => StateT s m a
                 -> MultiStateT ss m a
    inflateState :: forall (m :: * -> *) s (ss :: [*]) a.
    (Monad m, ContainsType s ss) =>
    StateT s m a -> MultiStateT ss m a
    inflateState StateT s m a
    k = do
      s
    s <- MultiStateT ss m s
    forall a (m :: * -> *). MonadMultiGet a m => m a
    mGet
      ~(a
    x, s
    s') <- m (a, s) -> MultiStateT ss m (a, s)
    forall (m :: * -> *) a. Monad m => m a -> MultiStateT ss m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m (a, s) -> MultiStateT ss m (a, s))
    -> m (a, s) -> MultiStateT ss m (a, s)
    forall a b. (a -> b) -> a -> b
    $ StateT s m a -> s -> m (a, s)
    forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
    runStateT StateT s m a
    k s
    s
      s -> MultiStateT ss m ()
    forall a (m :: * -> *). MonadMultiState a m => a -> m ()
    mSet s
    s'
      a -> MultiStateT ss m a
    forall a. a -> MultiStateT ss m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return a
    x

    inflateReader :: (Monad m, ContainsType r ss)
                  => ReaderT r m a
                  -> MultiStateT ss m a
    inflateReader :: forall (m :: * -> *) r (ss :: [*]) a.
    (Monad m, ContainsType r ss) =>
    ReaderT r m a -> MultiStateT ss m a
    inflateReader ReaderT r m a
    k = MultiStateT ss m r
    forall a (m :: * -> *). MonadMultiGet a m => m a
    mGet MultiStateT ss m r
    -> (r -> MultiStateT ss m a) -> MultiStateT ss m a
    forall a b.
    MultiStateT ss m a
    -> (a -> MultiStateT ss m b) -> MultiStateT ss m b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= m a -> MultiStateT ss m a
    forall (m :: * -> *) a. Monad m => m a -> MultiStateT ss m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m a -> MultiStateT ss m a)
    -> (r -> m a) -> r -> MultiStateT ss m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT r m a -> r -> m a
    forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
    runReaderT ReaderT r m a
    k

    inflateWriter :: (Monad m, ContainsType w ss, Monoid w)
                  => WriterT w m a
                  -> MultiStateT ss m a
    inflateWriter :: forall (m :: * -> *) w (ss :: [*]) a.
    (Monad m, ContainsType w ss, Monoid w) =>
    WriterT w m a -> MultiStateT ss m a
    inflateWriter WriterT w m a
    k = do
      ~(a
    x, w
    w) <- m (a, w) -> MultiStateT ss m (a, w)
    forall (m :: * -> *) a. Monad m => m a -> MultiStateT ss m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m (a, w) -> MultiStateT ss m (a, w))
    -> m (a, w) -> MultiStateT ss m (a, w)
    forall a b. (a -> b) -> a -> b
    $ WriterT w m a -> m (a, w)
    forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
    runWriterT WriterT w m a
    k
      w -> MultiStateT ss m ()
    forall a (m :: * -> *). MonadMultiState a m => a -> m ()
    mSet w
    w
      a -> MultiStateT ss m a
    forall a. a -> MultiStateT ss m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return a
    x

    -- foreign lifting instances

    instance (MonadState s m) => MonadState s (MultiStateT c m) where
      put :: s -> MultiStateT c m ()
    put   = m () -> MultiStateT c m ()
    forall (m :: * -> *) a. Monad m => m a -> MultiStateT c m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m () -> MultiStateT c m ())
    -> (s -> m ()) -> s -> MultiStateT c m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . s -> m ()
    forall s (m :: * -> *). MonadState s m => s -> m ()
    put
      get :: MultiStateT c m s
    get   = m s -> MultiStateT c m s
    forall (m :: * -> *) a. Monad m => m a -> MultiStateT c m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m s -> MultiStateT c m s) -> m s -> MultiStateT c m s
    forall a b. (a -> b) -> a -> b
    $ m s
    forall s (m :: * -> *). MonadState s m => m s
    get
      state :: forall a. (s -> (a, s)) -> MultiStateT c m a
    state = m a -> MultiStateT c m a
    forall (m :: * -> *) a. Monad m => m a -> MultiStateT c m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m a -> MultiStateT c m a)
    -> ((s -> (a, s)) -> m a) -> (s -> (a, s)) -> MultiStateT c m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (s -> (a, s)) -> m a
    forall a. (s -> (a, s)) -> m a
    forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
    state

    instance (MonadWriter w m) => MonadWriter w (MultiStateT c m) where
      writer :: forall a. (a, w) -> MultiStateT c m a
    writer = m a -> MultiStateT c m a
    forall (m :: * -> *) a. Monad m => m a -> MultiStateT c m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m a -> MultiStateT c m a)
    -> ((a, w) -> m a) -> (a, w) -> MultiStateT c m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (a, w) -> m a
    forall a. (a, w) -> m a
    forall w (m :: * -> *) a. MonadWriter w m => (a, w) -> m a
    writer
      tell :: w -> MultiStateT c m ()
    tell   = m () -> MultiStateT c m ()
    forall (m :: * -> *) a. Monad m => m a -> MultiStateT c m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m () -> MultiStateT c m ())
    -> (w -> m ()) -> w -> MultiStateT c m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . w -> m ()
    forall w (m :: * -> *). MonadWriter w m => w -> m ()
    tell
      listen :: forall a. MultiStateT c m a -> MultiStateT c m (a, w)
    listen = StateT (HList c) m (a, w) -> MultiStateT c m (a, w)
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList c) m (a, w) -> MultiStateT c m (a, w))
    -> (MultiStateT c m a -> StateT (HList c) m (a, w))
    -> MultiStateT c m a
    -> MultiStateT c m (a, w)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
        (m (a, HList c) -> m ((a, w), HList c))
    -> StateT (HList c) m a -> StateT (HList c) m (a, w)
    forall (m :: * -> *) a s (n :: * -> *) b.
    (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
    mapStateT ((((a, HList c), w) -> ((a, w), HList c))
    -> m ((a, HList c), w) -> m ((a, w), HList c)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM (\(~(~(a
    a,HList c
    w), w
    w')) -> ((a
    a, w
    w'), HList c
    w)) (m ((a, HList c), w) -> m ((a, w), HList c))
    -> (m (a, HList c) -> m ((a, HList c), w))
    -> m (a, HList c)
    -> m ((a, w), HList c)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . m (a, HList c) -> m ((a, HList c), w)
    forall a. m a -> m (a, w)
    forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
    listen) (StateT (HList c) m a -> StateT (HList c) m (a, w))
    -> (MultiStateT c m a -> StateT (HList c) m a)
    -> MultiStateT c m a
    -> StateT (HList c) m (a, w)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
        MultiStateT c m a -> StateT (HList c) m a
    forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw
      pass :: forall a. MultiStateT c m (a, w -> w) -> MultiStateT c m a
    pass = StateT (HList c) m a -> MultiStateT c m a
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList c) m a -> MultiStateT c m a)
    -> (MultiStateT c m (a, w -> w) -> StateT (HList c) m a)
    -> MultiStateT c m (a, w -> w)
    -> MultiStateT c m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
        (m ((a, w -> w), HList c) -> m (a, HList c))
    -> StateT (HList c) m (a, w -> w) -> StateT (HList c) m a
    forall (m :: * -> *) a s (n :: * -> *) b.
    (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
    mapStateT (m ((a, HList c), w -> w) -> m (a, HList c)
    forall a. m (a, w -> w) -> m a
    forall w (m :: * -> *) a. MonadWriter w m => m (a, w -> w) -> m a
    pass (m ((a, HList c), w -> w) -> m (a, HList c))
    -> (m ((a, w -> w), HList c) -> m ((a, HList c), w -> w))
    -> m ((a, w -> w), HList c)
    -> m (a, HList c)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (((a, w -> w), HList c) -> ((a, HList c), w -> w))
    -> m ((a, w -> w), HList c) -> m ((a, HList c), w -> w)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM (\(~(~(a
    a, w -> w
    f), HList c
    w)) -> ((a
    a, HList c
    w), w -> w
    f))) (StateT (HList c) m (a, w -> w) -> StateT (HList c) m a)
    -> (MultiStateT c m (a, w -> w) -> StateT (HList c) m (a, w -> w))
    -> MultiStateT c m (a, w -> w)
    -> StateT (HList c) m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
        MultiStateT c m (a, w -> w) -> StateT (HList c) m (a, w -> w)
    forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw

    instance MonadIO m => MonadIO (MultiStateT c m) where
      liftIO :: forall a. IO a -> MultiStateT c m a
    liftIO = m a -> MultiStateT c m a
    forall (m :: * -> *) a. Monad m => m a -> MultiStateT c m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m a -> MultiStateT c m a)
    -> (IO a -> m a) -> IO a -> MultiStateT c m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . IO a -> m a
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO

    instance (Functor m, Applicative m, MonadPlus m) => Alternative (MultiStateT s m) where
      empty :: forall a. MultiStateT s m a
    empty = m a -> MultiStateT s m a
    forall (m :: * -> *) a. Monad m => m a -> MultiStateT s m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift m a
    forall a. m a
    forall (m :: * -> *) a. MonadPlus m => m a
    mzero
      MultiStateT StateT (HList s) m a
    m <|> :: forall a.
    MultiStateT s m a -> MultiStateT s m a -> MultiStateT s m a
    <|> MultiStateT StateT (HList s) m a
    n = StateT (HList s) m a -> MultiStateT s m a
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList s) m a -> MultiStateT s m a)
    -> StateT (HList s) m a -> MultiStateT s m a
    forall a b. (a -> b) -> a -> b
    $ StateT (HList s) m a
    m StateT (HList s) m a
    -> StateT (HList s) m a -> StateT (HList s) m a
    forall a.
    StateT (HList s) m a
    -> StateT (HList s) m a -> StateT (HList s) m a
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    <|> StateT (HList s) m a
    n

    instance MonadPlus m => MonadPlus (MultiStateT s m) where
      mzero :: forall a. MultiStateT s m a
    mzero = StateT (HList s) m a -> MultiStateT s m a
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList s) m a -> MultiStateT s m a)
    -> StateT (HList s) m a -> MultiStateT s m a
    forall a b. (a -> b) -> a -> b
    $ StateT (HList s) m a
    forall a. StateT (HList s) m a
    forall (m :: * -> *) a. MonadPlus m => m a
    mzero
      MultiStateT StateT (HList s) m a
    m mplus :: forall a.
    MultiStateT s m a -> MultiStateT s m a -> MultiStateT s m a
    `mplus` MultiStateT StateT (HList s) m a
    n = StateT (HList s) m a -> MultiStateT s m a
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList s) m a -> MultiStateT s m a)
    -> StateT (HList s) m a -> MultiStateT s m a
    forall a b. (a -> b) -> a -> b
    $ StateT (HList s) m a
    m StateT (HList s) m a
    -> StateT (HList s) m a -> StateT (HList s) m a
    forall a.
    StateT (HList s) m a
    -> StateT (HList s) m a -> StateT (HList s) m a
    forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
    `mplus` StateT (HList s) m a
    n

    instance MonadBase b m => MonadBase b (MultiStateT s m) where
      liftBase :: forall α. b α -> MultiStateT s m α
    liftBase = b α -> MultiStateT s m α
    forall (t :: (* -> *) -> * -> *) (b :: * -> *) (m :: * -> *) α.
    (MonadTrans t, MonadBase b m) =>
    b α -> t m α
    liftBaseDefault

    instance MonadTransControl (MultiStateT s) where
      type StT (MultiStateT s) a = (a, HList s)
      liftWith :: forall (m :: * -> *) a.
    Monad m =>
    (Run (MultiStateT s) -> m a) -> MultiStateT s m a
    liftWith Run (MultiStateT s) -> m a
    f = StateT (HList s) m a -> MultiStateT s m a
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList s) m a -> MultiStateT s m a)
    -> StateT (HList s) m a -> MultiStateT s m a
    forall a b. (a -> b) -> a -> b
    $ (Run (StateT (HList s)) -> m a) -> StateT (HList s) m a
    forall (m :: * -> *) a.
    Monad m =>
    (Run (StateT (HList s)) -> m a) -> StateT (HList s) m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTransControl t, Monad m) =>
    (Run t -> m a) -> t m a
    liftWith ((Run (StateT (HList s)) -> m a) -> StateT (HList s) m a)
    -> (Run (StateT (HList s)) -> m a) -> StateT (HList s) m a
    forall a b. (a -> b) -> a -> b
    $ \Run (StateT (HList s))
    s -> Run (MultiStateT s) -> m a
    f (Run (MultiStateT s) -> m a) -> Run (MultiStateT s) -> m a
    forall a b. (a -> b) -> a -> b
    $ \MultiStateT s n b
    r -> StateT (HList s) n b -> n (StT (StateT (HList s)) b)
    Run (StateT (HList s))
    s (StateT (HList s) n b -> n (StT (StateT (HList s)) b))
    -> StateT (HList s) n b -> n (StT (StateT (HList s)) b)
    forall a b. (a -> b) -> a -> b
    $ MultiStateT s n b -> StateT (HList s) n b
    forall (x :: [*]) (m :: * -> *) a.
    MultiStateT x m a -> StateT (HList x) m a
    runMultiStateTRaw MultiStateT s n b
    r
      restoreT :: forall (m :: * -> *) a.
    Monad m =>
    m (StT (MultiStateT s) a) -> MultiStateT s m a
    restoreT = StateT (HList s) m a -> MultiStateT s m a
    forall (x :: [*]) (m :: * -> *) a.
    StateT (HList x) m a -> MultiStateT x m a
    MultiStateT (StateT (HList s) m a -> MultiStateT s m a)
    -> (m (a, HList s) -> StateT (HList s) m a)
    -> m (a, HList s)
    -> MultiStateT s m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . m (a, HList s) -> StateT (HList s) m a
    m (StT (StateT (HList s)) a) -> StateT (HList s) m a
    forall (m :: * -> *) a.
    Monad m =>
    m (StT (StateT (HList s)) a) -> StateT (HList s) m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTransControl t, Monad m) =>
    m (StT t a) -> t m a
    restoreT

    instance MonadBaseControl b m => MonadBaseControl b (MultiStateT s m) where
      type StM (MultiStateT s m) a = ComposeSt (MultiStateT s) m a
      liftBaseWith :: forall a.
    (RunInBase (MultiStateT s m) b -> b a) -> MultiStateT s m a
    liftBaseWith = (RunInBaseDefault (MultiStateT s) m b -> b a) -> MultiStateT s m a
    (RunInBase (MultiStateT s m) b -> b a) -> MultiStateT s m a
    forall (t :: (* -> *) -> * -> *) (b :: * -> *) (m :: * -> *) a.
    (MonadTransControl t, MonadBaseControl b m) =>
    (RunInBaseDefault t m b -> b a) -> t m a
    defaultLiftBaseWith
      restoreM :: forall a. StM (MultiStateT s m) a -> MultiStateT s m a
    restoreM = ComposeSt (MultiStateT s) m a -> MultiStateT s m a
    StM (MultiStateT s m) a -> MultiStateT s m a
    forall (t :: (* -> *) -> * -> *) (b :: * -> *) (m :: * -> *) a.
    (MonadTransControl t, MonadBaseControl b m) =>
    ComposeSt t m a -> t m a
    defaultRestoreM