    {-# LANGUAGE FlexibleContexts #-}
    {-# LANGUAGE FlexibleInstances #-}
    {-# LANGUAGE KindSignatures #-}
    {-# LANGUAGE MultiParamTypeClasses #-}
    {-# LANGUAGE UndecidableInstances #-}
    {-# LANGUAGE CPP #-}

    #if __GLASGOW_HASKELL__ >= 806
    {-# LANGUAGE QuantifiedConstraints #-}
    #endif

    {-| Composition of monad transformers. A higher-order version of
        "Data.Functor.Compose".
    -}

    module Control.Monad.Trans.Compose (
        -- * ComposeT
        ComposeT(ComposeT, getComposeT),
        mapComposeT
       ) where

    import Control.Applicative (
        Applicative(pure, (<*>), (*>), (<*)), Alternative(empty, (<|>)) )
    import Control.Monad (MonadPlus(mzero, mplus), liftM)
    import Control.Monad.Cont.Class (MonadCont(callCC))
    import Control.Monad.Error.Class (MonadError(throwError, catchError))
    import Control.Monad.Morph (MFunctor(hoist))
    import Control.Monad.RWS.Class (MonadRWS)
    import Control.Monad.Reader.Class (MonadReader(ask, local, reader))
    import Control.Monad.State.Class (MonadState(get, put, state))
    import Control.Monad.Trans.Class (MonadTrans(lift))
    import Control.Monad.Writer.Class (MonadWriter(writer, tell, listen, pass))
    import Control.Monad.IO.Class (MonadIO(liftIO))
    import Data.Foldable (Foldable(fold, foldMap, foldr, foldl, foldr1, foldl1))
    import Data.Traversable (Traversable(traverse, sequenceA, mapM, sequence))
    import Prelude hiding (foldr, foldl, foldr1, foldl1, mapM, sequence)

    #if __GLASGOW_HASKELL__ >= 800
    import Control.Monad.Fail (MonadFail(..))
    import qualified Control.Monad.Fail
    #endif

    infixr 9 `ComposeT`

    -- | Composition of monad transformers.
    newtype ComposeT (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *) m a
        = ComposeT { ComposeT f g m a -> f (g m) a
    getComposeT :: f (g m) a }
      deriving (ComposeT f g m a -> ComposeT f g m a -> Bool
    (ComposeT f g m a -> ComposeT f g m a -> Bool)
    -> (ComposeT f g m a -> ComposeT f g m a -> Bool)
    -> Eq (ComposeT f g m a)
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Eq (f (g m) a) =>
    ComposeT f g m a -> ComposeT f g m a -> Bool
    /= :: ComposeT f g m a -> ComposeT f g m a -> Bool
    $c/= :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Eq (f (g m) a) =>
    ComposeT f g m a -> ComposeT f g m a -> Bool
    == :: ComposeT f g m a -> ComposeT f g m a -> Bool
    $c== :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Eq (f (g m) a) =>
    ComposeT f g m a -> ComposeT f g m a -> Bool
    Eq, Eq (ComposeT f g m a)
    Eq (ComposeT f g m a) =>
    (ComposeT f g m a -> ComposeT f g m a -> Ordering)
    -> (ComposeT f g m a -> ComposeT f g m a -> Bool)
    -> (ComposeT f g m a -> ComposeT f g m a -> Bool)
    -> (ComposeT f g m a -> ComposeT f g m a -> Bool)
    -> (ComposeT f g m a -> ComposeT f g m a -> Bool)
    -> (ComposeT f g m a -> ComposeT f g m a -> ComposeT f g m a)
    -> (ComposeT f g m a -> ComposeT f g m a -> ComposeT f g m a)
    -> Ord (ComposeT f g m a)
    ComposeT f g m a -> ComposeT f g m a -> Bool
    ComposeT f g m a -> ComposeT f g m a -> Ordering
    ComposeT f g m a -> ComposeT f g m a -> ComposeT f g m a
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Ord (f (g m) a) =>
    Eq (ComposeT f g m a)
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Ord (f (g m) a) =>
    ComposeT f g m a -> ComposeT f g m a -> Bool
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Ord (f (g m) a) =>
    ComposeT f g m a -> ComposeT f g m a -> Ordering
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Ord (f (g m) a) =>
    ComposeT f g m a -> ComposeT f g m a -> ComposeT f g m a
    min :: ComposeT f g m a -> ComposeT f g m a -> ComposeT f g m a
    $cmin :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Ord (f (g m) a) =>
    ComposeT f g m a -> ComposeT f g m a -> ComposeT f g m a
    max :: ComposeT f g m a -> ComposeT f g m a -> ComposeT f g m a
    $cmax :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Ord (f (g m) a) =>
    ComposeT f g m a -> ComposeT f g m a -> ComposeT f g m a
    >= :: ComposeT f g m a -> ComposeT f g m a -> Bool
    $c>= :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Ord (f (g m) a) =>
    ComposeT f g m a -> ComposeT f g m a -> Bool
    > :: ComposeT f g m a -> ComposeT f g m a -> Bool
    $c> :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Ord (f (g m) a) =>
    ComposeT f g m a -> ComposeT f g m a -> Bool
    <= :: ComposeT f g m a -> ComposeT f g m a -> Bool
    $c<= :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Ord (f (g m) a) =>
    ComposeT f g m a -> ComposeT f g m a -> Bool
    < :: ComposeT f g m a -> ComposeT f g m a -> Bool
    $c< :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Ord (f (g m) a) =>
    ComposeT f g m a -> ComposeT f g m a -> Bool
    compare :: ComposeT f g m a -> ComposeT f g m a -> Ordering
    $ccompare :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Ord (f (g m) a) =>
    ComposeT f g m a -> ComposeT f g m a -> Ordering
    $cp1Ord :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Ord (f (g m) a) =>
    Eq (ComposeT f g m a)
    Ord, ReadPrec [ComposeT f g m a]
    ReadPrec (ComposeT f g m a)
    Int -> ReadS (ComposeT f g m a)
    ReadS [ComposeT f g m a]
    (Int -> ReadS (ComposeT f g m a))
    -> ReadS [ComposeT f g m a]
    -> ReadPrec (ComposeT f g m a)
    -> ReadPrec [ComposeT f g m a]
    -> Read (ComposeT f g m a)
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Read (f (g m) a) =>
    ReadPrec [ComposeT f g m a]
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Read (f (g m) a) =>
    ReadPrec (ComposeT f g m a)
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Read (f (g m) a) =>
    Int -> ReadS (ComposeT f g m a)
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Read (f (g m) a) =>
    ReadS [ComposeT f g m a]
    readListPrec :: ReadPrec [ComposeT f g m a]
    $creadListPrec :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Read (f (g m) a) =>
    ReadPrec [ComposeT f g m a]
    readPrec :: ReadPrec (ComposeT f g m a)
    $creadPrec :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Read (f (g m) a) =>
    ReadPrec (ComposeT f g m a)
    readList :: ReadS [ComposeT f g m a]
    $creadList :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Read (f (g m) a) =>
    ReadS [ComposeT f g m a]
    readsPrec :: Int -> ReadS (ComposeT f g m a)
    $creadsPrec :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Read (f (g m) a) =>
    Int -> ReadS (ComposeT f g m a)
    Read, Int -> ComposeT f g m a -> ShowS
    [ComposeT f g m a] -> ShowS
    ComposeT f g m a -> String
    (Int -> ComposeT f g m a -> ShowS)
    -> (ComposeT f g m a -> String)
    -> ([ComposeT f g m a] -> ShowS)
    -> Show (ComposeT f g m a)
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Show (f (g m) a) =>
    Int -> ComposeT f g m a -> ShowS
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Show (f (g m) a) =>
    [ComposeT f g m a] -> ShowS
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Show (f (g m) a) =>
    ComposeT f g m a -> String
    showList :: [ComposeT f g m a] -> ShowS
    $cshowList :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Show (f (g m) a) =>
    [ComposeT f g m a] -> ShowS
    show :: ComposeT f g m a -> String
    $cshow :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Show (f (g m) a) =>
    ComposeT f g m a -> String
    showsPrec :: Int -> ComposeT f g m a -> ShowS
    $cshowsPrec :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    Show (f (g m) a) =>
    Int -> ComposeT f g m a -> ShowS
    Show)

    instance (MFunctor f, MonadTrans f, MonadTrans g) => MonadTrans (ComposeT f g)
      where
        lift :: m a -> ComposeT f g m a
    lift = f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) a -> ComposeT f g m a)
    -> (m a -> f (g m) a) -> m a -> ComposeT f g m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (forall a. m a -> g m a) -> f m a -> f (g m) a
    forall k (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
           (b :: k).
    (MFunctor t, Monad m) =>
    (forall a. m a -> n a) -> t m b -> t n b
    hoist forall a. m a -> g m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (f m a -> f (g m) a) -> (m a -> f m a) -> m a -> f (g m) a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . m a -> f m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift

    #if __GLASGOW_HASKELL__ >= 806
    instance (MFunctor f, MFunctor g, forall m. Monad m => Monad (g m))
        => MFunctor (ComposeT f g) where
        hoist :: (forall a. m a -> n a) -> ComposeT f g m b -> ComposeT f g n b
    hoist f :: forall a. m a -> n a
    f (ComposeT m :: f (g m) b
    m) = f (g n) b -> ComposeT f g n b
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT ((forall a. g m a -> g n a) -> f (g m) b -> f (g n) b
    forall k (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
           (b :: k).
    (MFunctor t, Monad m) =>
    (forall a. m a -> n a) -> t m b -> t n b
    hoist ((forall a. m a -> n a) -> g m a -> g n a
    forall k (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
           (b :: k).
    (MFunctor t, Monad m) =>
    (forall a. m a -> n a) -> t m b -> t n b
    hoist forall a. m a -> n a
    f) f (g m) b
    m)
    #endif

    instance Functor (f (g m)) => Functor (ComposeT f g m) where
        fmap :: (a -> b) -> ComposeT f g m a -> ComposeT f g m b
    fmap f :: a -> b
    f (ComposeT m :: f (g m) a
    m) = f (g m) b -> ComposeT f g m b
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT ((a -> b) -> f (g m) a -> f (g m) b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap a -> b
    f f (g m) a
    m)

    instance Applicative (f (g m)) => Applicative (ComposeT f g m) where
        pure :: a -> ComposeT f g m a
    pure a :: a
    a = f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (a -> f (g m) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure a
    a)
        ComposeT f :: f (g m) (a -> b)
    f <*> :: ComposeT f g m (a -> b) -> ComposeT f g m a -> ComposeT f g m b
    <*> ComposeT a :: f (g m) a
    a = f (g m) b -> ComposeT f g m b
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) (a -> b)
    f f (g m) (a -> b) -> f (g m) a -> f (g m) b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> f (g m) a
    a)
        ComposeT a :: f (g m) a
    a *> :: ComposeT f g m a -> ComposeT f g m b -> ComposeT f g m b
    *> ComposeT b :: f (g m) b
    b = f (g m) b -> ComposeT f g m b
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) a
    a f (g m) a -> f (g m) b -> f (g m) b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> f (g m) b
    b)
        ComposeT a :: f (g m) a
    a <* :: ComposeT f g m a -> ComposeT f g m b -> ComposeT f g m a
    <* ComposeT b :: f (g m) b
    b = f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) a
    a f (g m) a -> f (g m) b -> f (g m) a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* f (g m) b
    b)

    instance Alternative (f (g m)) => Alternative (ComposeT f g m) where
        empty :: ComposeT f g m a
    empty = f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT f (g m) a
    forall (f :: * -> *) a. Alternative f => f a
    empty
        ComposeT a :: f (g m) a
    a <|> :: ComposeT f g m a -> ComposeT f g m a -> ComposeT f g m a
    <|> ComposeT b :: f (g m) a
    b = f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) a
    a f (g m) a -> f (g m) a -> f (g m) a
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    <|> f (g m) a
    b)

    instance Monad (f (g m)) => Monad (ComposeT f g m) where
        return :: a -> ComposeT f g m a
    return a :: a
    a = f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (a -> f (g m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return a
    a)
        m :: ComposeT f g m a
    m >>= :: ComposeT f g m a -> (a -> ComposeT f g m b) -> ComposeT f g m b
    >>= f :: a -> ComposeT f g m b
    f  = f (g m) b -> ComposeT f g m b
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (ComposeT f g m a -> f (g m) a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    ComposeT f g m a -> f (g m) a
    getComposeT ComposeT f g m a
    m f (g m) a -> (a -> f (g m) b) -> f (g m) b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \x :: a
    x -> ComposeT f g m b -> f (g m) b
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    ComposeT f g m a -> f (g m) a
    getComposeT (a -> ComposeT f g m b
    f a
    x))
    #if __GLASGOW_HASKELL__ < 808
        fail e   = ComposeT (Prelude.fail e)
    #endif

    #if __GLASGOW_HASKELL__ >= 800
    instance MonadFail (f (g m)) => MonadFail (ComposeT f g m) where
        fail :: String -> ComposeT f g m a
    fail e :: String
    e = f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (String -> f (g m) a
    forall (m :: * -> *) a. MonadFail m => String -> m a
    Control.Monad.Fail.fail String
    e)
    #endif

    instance MonadPlus (f (g m)) => MonadPlus (ComposeT f g m) where
        mzero :: ComposeT f g m a
    mzero = f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT f (g m) a
    forall (m :: * -> *) a. MonadPlus m => m a
    mzero
        ComposeT a :: f (g m) a
    a mplus :: ComposeT f g m a -> ComposeT f g m a -> ComposeT f g m a
    `mplus` ComposeT b :: f (g m) a
    b = f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) a
    a f (g m) a -> f (g m) a -> f (g m) a
    forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
    `mplus` f (g m) a
    b)

    instance MonadIO (f (g m)) => MonadIO (ComposeT f g m) where
        liftIO :: IO a -> ComposeT f g m a
    liftIO m :: IO a
    m = f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (IO a -> f (g m) a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO IO a
    m)

    instance Foldable (f (g m)) => Foldable (ComposeT f g m) where
        fold :: ComposeT f g m m -> m
    fold        (ComposeT m :: f (g m) m
    m) = f (g m) m -> m
    forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
    fold f (g m) m
    m
        foldMap :: (a -> m) -> ComposeT f g m a -> m
    foldMap f :: a -> m
    f   (ComposeT m :: f (g m) a
    m) = (a -> m) -> f (g m) a -> m
    forall (t :: * -> *) m a.
    (Foldable t, Monoid m) =>
    (a -> m) -> t a -> m
    foldMap a -> m
    f   f (g m) a
    m
        foldr :: (a -> b -> b) -> b -> ComposeT f g m a -> b
    foldr   f :: a -> b -> b
    f a :: b
    a (ComposeT m :: f (g m) a
    m) = (a -> b -> b) -> b -> f (g m) a -> b
    forall (t :: * -> *) a b.
    Foldable t =>
    (a -> b -> b) -> b -> t a -> b
    foldr   a -> b -> b
    f b
    a f (g m) a
    m
        foldl :: (b -> a -> b) -> b -> ComposeT f g m a -> b
    foldl   f :: b -> a -> b
    f a :: b
    a (ComposeT m :: f (g m) a
    m) = (b -> a -> b) -> b -> f (g m) a -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl   b -> a -> b
    f b
    a f (g m) a
    m
        foldr1 :: (a -> a -> a) -> ComposeT f g m a -> a
    foldr1 f :: a -> a -> a
    f    (ComposeT m :: f (g m) a
    m) = (a -> a -> a) -> f (g m) a -> a
    forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
    foldr1  a -> a -> a
    f   f (g m) a
    m
        foldl1 :: (a -> a -> a) -> ComposeT f g m a -> a
    foldl1 f :: a -> a -> a
    f    (ComposeT m :: f (g m) a
    m) = (a -> a -> a) -> f (g m) a -> a
    forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
    foldl1  a -> a -> a
    f   f (g m) a
    m

    instance Traversable (f (g m)) => Traversable (ComposeT f g m) where
        traverse :: (a -> f b) -> ComposeT f g m a -> f (ComposeT f g m b)
    traverse f :: a -> f b
    f (ComposeT m :: f (g m) a
    m) = (f (g m) b -> ComposeT f g m b)
    -> f (f (g m) b) -> f (ComposeT f g m b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap  f (g m) b -> ComposeT f g m b
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT ((a -> f b) -> f (g m) a -> f (f (g m) b)
    forall (t :: * -> *) (f :: * -> *) a b.
    (Traversable t, Applicative f) =>
    (a -> f b) -> t a -> f (t b)
    traverse a -> f b
    f f (g m) a
    m)
        sequenceA :: ComposeT f g m (f a) -> f (ComposeT f g m a)
    sequenceA  (ComposeT m :: f (g m) (f a)
    m) = (f (g m) a -> ComposeT f g m a)
    -> f (f (g m) a) -> f (ComposeT f g m a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap  f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) (f a) -> f (f (g m) a)
    forall (t :: * -> *) (f :: * -> *) a.
    (Traversable t, Applicative f) =>
    t (f a) -> f (t a)
    sequenceA  f (g m) (f a)
    m)
        mapM :: (a -> m b) -> ComposeT f g m a -> m (ComposeT f g m b)
    mapM     f :: a -> m b
    f (ComposeT m :: f (g m) a
    m) = (f (g m) b -> ComposeT f g m b)
    -> m (f (g m) b) -> m (ComposeT f g m b)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM f (g m) b -> ComposeT f g m b
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT ((a -> m b) -> f (g m) a -> m (f (g m) b)
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    mapM     a -> m b
    f f (g m) a
    m)
        sequence :: ComposeT f g m (m a) -> m (ComposeT f g m a)
    sequence   (ComposeT m :: f (g m) (m a)
    m) = (f (g m) a -> ComposeT f g m a)
    -> m (f (g m) a) -> m (ComposeT f g m a)
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) (m a) -> m (f (g m) a)
    forall (t :: * -> *) (m :: * -> *) a.
    (Traversable t, Monad m) =>
    t (m a) -> m (t a)
    sequence   f (g m) (m a)
    m)

    instance MonadCont (f (g m)) => MonadCont (ComposeT f g m) where
        callCC :: ((a -> ComposeT f g m b) -> ComposeT f g m a) -> ComposeT f g m a
    callCC f :: (a -> ComposeT f g m b) -> ComposeT f g m a
    f = f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) a -> ComposeT f g m a) -> f (g m) a -> ComposeT f g m a
    forall a b. (a -> b) -> a -> b
    $ ((a -> f (g m) b) -> f (g m) a) -> f (g m) a
    forall (m :: * -> *) a b. MonadCont m => ((a -> m b) -> m a) -> m a
    callCC (((a -> f (g m) b) -> f (g m) a) -> f (g m) a)
    -> ((a -> f (g m) b) -> f (g m) a) -> f (g m) a
    forall a b. (a -> b) -> a -> b
    $ \c :: a -> f (g m) b
    c -> ComposeT f g m a -> f (g m) a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    ComposeT f g m a -> f (g m) a
    getComposeT ((a -> ComposeT f g m b) -> ComposeT f g m a
    f (f (g m) b -> ComposeT f g m b
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) b -> ComposeT f g m b)
    -> (a -> f (g m) b) -> a -> ComposeT f g m b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> f (g m) b
    c))

    instance MonadError e (f (g m)) => MonadError e (ComposeT f g m) where
        throwError :: e -> ComposeT f g m a
    throwError     = f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) a -> ComposeT f g m a)
    -> (e -> f (g m) a) -> e -> ComposeT f g m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . e -> f (g m) a
    forall e (m :: * -> *) a. MonadError e m => e -> m a
    throwError
        catchError :: ComposeT f g m a -> (e -> ComposeT f g m a) -> ComposeT f g m a
    catchError m :: ComposeT f g m a
    m h :: e -> ComposeT f g m a
    h = f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) a -> ComposeT f g m a) -> f (g m) a -> ComposeT f g m a
    forall a b. (a -> b) -> a -> b
    $ f (g m) a -> (e -> f (g m) a) -> f (g m) a
    forall e (m :: * -> *) a.
    MonadError e m =>
    m a -> (e -> m a) -> m a
    catchError (ComposeT f g m a -> f (g m) a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    ComposeT f g m a -> f (g m) a
    getComposeT ComposeT f g m a
    m) (ComposeT f g m a -> f (g m) a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    ComposeT f g m a -> f (g m) a
    getComposeT (ComposeT f g m a -> f (g m) a)
    -> (e -> ComposeT f g m a) -> e -> f (g m) a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . e -> ComposeT f g m a
    h)

    instance MonadRWS r w s (f (g m)) => MonadRWS r w s (ComposeT f g m)

    instance MonadReader r (f (g m)) => MonadReader r (ComposeT f g m) where
        ask :: ComposeT f g m r
    ask    = f (g m) r -> ComposeT f g m r
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT f (g m) r
    forall r (m :: * -> *). MonadReader r m => m r
    ask
        local :: (r -> r) -> ComposeT f g m a -> ComposeT f g m a
    local  = (f (g m) a -> f (g m) a) -> ComposeT f g m a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a (p :: (* -> *) -> * -> *) (q :: (* -> *) -> * -> *)
           (n :: * -> *) b.
    (f (g m) a -> p (q n) b) -> ComposeT f g m a -> ComposeT p q n b
    mapComposeT ((f (g m) a -> f (g m) a) -> ComposeT f g m a -> ComposeT f g m a)
    -> ((r -> r) -> f (g m) a -> f (g m) a)
    -> (r -> r)
    -> ComposeT f g m a
    -> ComposeT f g m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (r -> r) -> f (g m) a -> f (g m) a
    forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
    local
        reader :: (r -> a) -> ComposeT f g m a
    reader = f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) a -> ComposeT f g m a)
    -> ((r -> a) -> f (g m) a) -> (r -> a) -> ComposeT f g m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (r -> a) -> f (g m) a
    forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
    reader

    instance MonadState s (f (g m)) => MonadState s (ComposeT f g m) where
        get :: ComposeT f g m s
    get   = f (g m) s -> ComposeT f g m s
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT f (g m) s
    forall s (m :: * -> *). MonadState s m => m s
    get
        put :: s -> ComposeT f g m ()
    put   = f (g m) () -> ComposeT f g m ()
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) () -> ComposeT f g m ())
    -> (s -> f (g m) ()) -> s -> ComposeT f g m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . s -> f (g m) ()
    forall s (m :: * -> *). MonadState s m => s -> m ()
    put
        state :: (s -> (a, s)) -> ComposeT f g m a
    state = f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) a -> ComposeT f g m a)
    -> ((s -> (a, s)) -> f (g m) a)
    -> (s -> (a, s))
    -> ComposeT f g m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (s -> (a, s)) -> f (g m) a
    forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
    state

    instance MonadWriter w (f (g m)) => MonadWriter w (ComposeT f g m) where
        writer :: (a, w) -> ComposeT f g m a
    writer = f (g m) a -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) a -> ComposeT f g m a)
    -> ((a, w) -> f (g m) a) -> (a, w) -> ComposeT f g m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (a, w) -> f (g m) a
    forall w (m :: * -> *) a. MonadWriter w m => (a, w) -> m a
    writer
        tell :: w -> ComposeT f g m ()
    tell   = f (g m) () -> ComposeT f g m ()
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (f (g m) () -> ComposeT f g m ())
    -> (w -> f (g m) ()) -> w -> ComposeT f g m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . w -> f (g m) ()
    forall w (m :: * -> *). MonadWriter w m => w -> m ()
    tell
        listen :: ComposeT f g m a -> ComposeT f g m (a, w)
    listen = (f (g m) a -> f (g m) (a, w))
    -> ComposeT f g m a -> ComposeT f g m (a, w)
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a (p :: (* -> *) -> * -> *) (q :: (* -> *) -> * -> *)
           (n :: * -> *) b.
    (f (g m) a -> p (q n) b) -> ComposeT f g m a -> ComposeT p q n b
    mapComposeT f (g m) a -> f (g m) (a, w)
    forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
    listen
        pass :: ComposeT f g m (a, w -> w) -> ComposeT f g m a
    pass   = (f (g m) (a, w -> w) -> f (g m) a)
    -> ComposeT f g m (a, w -> w) -> ComposeT f g m a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a (p :: (* -> *) -> * -> *) (q :: (* -> *) -> * -> *)
           (n :: * -> *) b.
    (f (g m) a -> p (q n) b) -> ComposeT f g m a -> ComposeT p q n b
    mapComposeT f (g m) (a, w -> w) -> f (g m) a
    forall w (m :: * -> *) a. MonadWriter w m => m (a, w -> w) -> m a
    pass

    -- | Transform the computation inside a 'ComposeT'.
    mapComposeT :: (f (g m) a -> p (q n) b) -> ComposeT f g m a -> ComposeT p q n b
    mapComposeT :: (f (g m) a -> p (q n) b) -> ComposeT f g m a -> ComposeT p q n b
    mapComposeT f :: f (g m) a -> p (q n) b
    f = p (q n) b -> ComposeT p q n b
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    f (g m) a -> ComposeT f g m a
    ComposeT (p (q n) b -> ComposeT p q n b)
    -> (ComposeT f g m a -> p (q n) b)
    -> ComposeT f g m a
    -> ComposeT p q n b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . f (g m) a -> p (q n) b
    f (f (g m) a -> p (q n) b)
    -> (ComposeT f g m a -> f (g m) a) -> ComposeT f g m a -> p (q n) b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ComposeT f g m a -> f (g m) a
    forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
           (m :: * -> *) a.
    ComposeT f g m a -> f (g m) a
    getComposeT