    {-# LANGUAGE CPP #-}
    #if __GLASGOW_HASKELL__ >= 702
    {-# LANGUAGE Safe #-}
    #endif
    #if __GLASGOW_HASKELL__ >= 710
    {-# LANGUAGE AutoDeriveTypeable #-}
    #endif
    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Control.Monad.Trans.List
    -- Copyright   :  (c) Andy Gill 2001,
    --                (c) Oregon Graduate Institute of Science and Technology, 2001
    -- License     :  BSD-style (see the file LICENSE)
    --
    -- Maintainer  :  R.Paterson@city.ac.uk
    -- Stability   :  experimental
    -- Portability :  portable
    --
    -- The ListT monad transformer, adding backtracking to a given monad,
    -- which must be commutative.
    -----------------------------------------------------------------------------

    module Control.Monad.Trans.List
      {-# DEPRECATED "This transformer is invalid on most monads" #-} (
        -- * The ListT monad transformer
        ListT(..),
        mapListT,
        -- * Lifting other operations
        liftCallCC,
        liftCatch,
      ) where

    import Control.Monad.IO.Class
    import Control.Monad.Signatures
    import Control.Monad.Trans.Class
    import Data.Functor.Classes
    #if MIN_VERSION_base(4,12,0)
    import Data.Functor.Contravariant
    #endif

    import Control.Applicative
    import Control.Monad
    #if MIN_VERSION_base(4,9,0)
    import qualified Control.Monad.Fail as Fail
    #endif
    import Control.Monad.Fix
    #if MIN_VERSION_base(4,4,0)
    import Control.Monad.Zip (MonadZip(mzipWith))
    #endif
    import Data.Foldable (Foldable(foldMap))
    import Data.Traversable (Traversable(traverse))

    -- | Parameterizable list monad, with an inner monad.
    --
    -- /Note:/ this does not yield a monad unless the argument monad is commutative.
    newtype ListT m a = ListT { forall (m :: * -> *) a. ListT m a -> m [a]
    runListT :: m [a] }

    instance (Eq1 m) => Eq1 (ListT m) where
        liftEq :: forall a b. (a -> b -> Bool) -> ListT m a -> ListT m b -> Bool
    liftEq a -> b -> Bool
    eq (ListT m [a]
    x) (ListT m [b]
    y) = ([a] -> [b] -> Bool) -> m [a] -> m [b] -> Bool
    forall a b. (a -> b -> Bool) -> m a -> m b -> Bool
    forall (f :: * -> *) a b.
    Eq1 f =>
    (a -> b -> Bool) -> f a -> f b -> Bool
    liftEq ((a -> b -> Bool) -> [a] -> [b] -> Bool
    forall a b. (a -> b -> Bool) -> [a] -> [b] -> Bool
    forall (f :: * -> *) a b.
    Eq1 f =>
    (a -> b -> Bool) -> f a -> f b -> Bool
    liftEq a -> b -> Bool
    eq) m [a]
    x m [b]
    y
        {-# INLINE liftEq #-}

    instance (Ord1 m) => Ord1 (ListT m) where
        liftCompare :: forall a b.
    (a -> b -> Ordering) -> ListT m a -> ListT m b -> Ordering
    liftCompare a -> b -> Ordering
    comp (ListT m [a]
    x) (ListT m [b]
    y) = ([a] -> [b] -> Ordering) -> m [a] -> m [b] -> Ordering
    forall a b. (a -> b -> Ordering) -> m a -> m b -> Ordering
    forall (f :: * -> *) a b.
    Ord1 f =>
    (a -> b -> Ordering) -> f a -> f b -> Ordering
    liftCompare ((a -> b -> Ordering) -> [a] -> [b] -> Ordering
    forall a b. (a -> b -> Ordering) -> [a] -> [b] -> Ordering
    forall (f :: * -> *) a b.
    Ord1 f =>
    (a -> b -> Ordering) -> f a -> f b -> Ordering
    liftCompare a -> b -> Ordering
    comp) m [a]
    x m [b]
    y
        {-# INLINE liftCompare #-}

    instance (Read1 m) => Read1 (ListT m) where
        liftReadsPrec :: forall a. (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (ListT m a)
    liftReadsPrec Int -> ReadS a
    rp ReadS [a]
    rl = (String -> ReadS (ListT m a)) -> Int -> ReadS (ListT m a)
    forall a. (String -> ReadS a) -> Int -> ReadS a
    readsData ((String -> ReadS (ListT m a)) -> Int -> ReadS (ListT m a))
    -> (String -> ReadS (ListT m a)) -> Int -> ReadS (ListT m a)
    forall a b. (a -> b) -> a -> b
    $
            (Int -> ReadS (m [a]))
    -> String -> (m [a] -> ListT m a) -> String -> ReadS (ListT m a)
    forall a t.
    (Int -> ReadS a) -> String -> (a -> t) -> String -> ReadS t
    readsUnaryWith ((Int -> ReadS [a]) -> ReadS [[a]] -> Int -> ReadS (m [a])
    forall a. (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (m a)
    forall (f :: * -> *) a.
    Read1 f =>
    (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
    liftReadsPrec Int -> ReadS [a]
    rp' ReadS [[a]]
    rl') String
    "ListT" m [a] -> ListT m a
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT
          where
            rp' :: Int -> ReadS [a]
    rp' = (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS [a]
    forall a. (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS [a]
    forall (f :: * -> *) a.
    Read1 f =>
    (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
    liftReadsPrec Int -> ReadS a
    rp ReadS [a]
    rl
            rl' :: ReadS [[a]]
    rl' = (Int -> ReadS a) -> ReadS [a] -> ReadS [[a]]
    forall a. (Int -> ReadS a) -> ReadS [a] -> ReadS [[a]]
    forall (f :: * -> *) a.
    Read1 f =>
    (Int -> ReadS a) -> ReadS [a] -> ReadS [f a]
    liftReadList Int -> ReadS a
    rp ReadS [a]
    rl

    instance (Show1 m) => Show1 (ListT m) where
        liftShowsPrec :: forall a.
    (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> ListT m a -> ShowS
    liftShowsPrec Int -> a -> ShowS
    sp [a] -> ShowS
    sl Int
    d (ListT m [a]
    m) =
            (Int -> m [a] -> ShowS) -> String -> Int -> m [a] -> ShowS
    forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
    showsUnaryWith ((Int -> [a] -> ShowS) -> ([[a]] -> ShowS) -> Int -> m [a] -> ShowS
    forall a.
    (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> m a -> ShowS
    forall (f :: * -> *) a.
    Show1 f =>
    (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
    liftShowsPrec Int -> [a] -> ShowS
    sp' [[a]] -> ShowS
    sl') String
    "ListT" Int
    d m [a]
    m
          where
            sp' :: Int -> [a] -> ShowS
    sp' = (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> [a] -> ShowS
    forall a.
    (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> [a] -> ShowS
    forall (f :: * -> *) a.
    Show1 f =>
    (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
    liftShowsPrec Int -> a -> ShowS
    sp [a] -> ShowS
    sl
            sl' :: [[a]] -> ShowS
    sl' = (Int -> a -> ShowS) -> ([a] -> ShowS) -> [[a]] -> ShowS
    forall a. (Int -> a -> ShowS) -> ([a] -> ShowS) -> [[a]] -> ShowS
    forall (f :: * -> *) a.
    Show1 f =>
    (Int -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS
    liftShowList Int -> a -> ShowS
    sp [a] -> ShowS
    sl

    instance (Eq1 m, Eq a) => Eq (ListT m a) where == :: ListT m a -> ListT m a -> Bool
    (==) = ListT m a -> ListT m a -> Bool
    forall (f :: * -> *) a. (Eq1 f, Eq a) => f a -> f a -> Bool
    eq1
    instance (Ord1 m, Ord a) => Ord (ListT m a) where compare :: ListT m a -> ListT m a -> Ordering
    compare = ListT m a -> ListT m a -> Ordering
    forall (f :: * -> *) a. (Ord1 f, Ord a) => f a -> f a -> Ordering
    compare1
    instance (Read1 m, Read a) => Read (ListT m a) where readsPrec :: Int -> ReadS (ListT m a)
    readsPrec = Int -> ReadS (ListT m a)
    forall (f :: * -> *) a. (Read1 f, Read a) => Int -> ReadS (f a)
    readsPrec1
    instance (Show1 m, Show a) => Show (ListT m a) where showsPrec :: Int -> ListT m a -> ShowS
    showsPrec = Int -> ListT m a -> ShowS
    forall (f :: * -> *) a. (Show1 f, Show a) => Int -> f a -> ShowS
    showsPrec1

    -- | Map between 'ListT' computations.
    --
    -- * @'runListT' ('mapListT' f m) = f ('runListT' m)@
    mapListT :: (m [a] -> n [b]) -> ListT m a -> ListT n b
    mapListT :: forall (m :: * -> *) a (n :: * -> *) b.
    (m [a] -> n [b]) -> ListT m a -> ListT n b
    mapListT m [a] -> n [b]
    f ListT m a
    m = n [b] -> ListT n b
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (n [b] -> ListT n b) -> n [b] -> ListT n b
    forall a b. (a -> b) -> a -> b
    $ m [a] -> n [b]
    f (ListT m a -> m [a]
    forall (m :: * -> *) a. ListT m a -> m [a]
    runListT ListT m a
    m)
    {-# INLINE mapListT #-}

    instance (Functor m) => Functor (ListT m) where
        fmap :: forall a b. (a -> b) -> ListT m a -> ListT m b
    fmap a -> b
    f = (m [a] -> m [b]) -> ListT m a -> ListT m b
    forall (m :: * -> *) a (n :: * -> *) b.
    (m [a] -> n [b]) -> ListT m a -> ListT n b
    mapListT ((m [a] -> m [b]) -> ListT m a -> ListT m b)
    -> (m [a] -> m [b]) -> ListT m a -> ListT m b
    forall a b. (a -> b) -> a -> b
    $ ([a] -> [b]) -> m [a] -> m [b]
    forall a b. (a -> b) -> m a -> m b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (([a] -> [b]) -> m [a] -> m [b]) -> ([a] -> [b]) -> m [a] -> m [b]
    forall a b. (a -> b) -> a -> b
    $ (a -> b) -> [a] -> [b]
    forall a b. (a -> b) -> [a] -> [b]
    map a -> b
    f
        {-# INLINE fmap #-}

    instance (Foldable f) => Foldable (ListT f) where
        foldMap :: forall m a. Monoid m => (a -> m) -> ListT f a -> m
    foldMap a -> m
    f (ListT f [a]
    a) = ([a] -> m) -> f [a] -> m
    forall m a. Monoid m => (a -> m) -> f a -> m
    forall (t :: * -> *) m a.
    (Foldable t, Monoid m) =>
    (a -> m) -> t a -> m
    foldMap ((a -> m) -> [a] -> m
    forall m a. Monoid m => (a -> m) -> [a] -> m
    forall (t :: * -> *) m a.
    (Foldable t, Monoid m) =>
    (a -> m) -> t a -> m
    foldMap a -> m
    f) f [a]
    a
        {-# INLINE foldMap #-}

    instance (Traversable f) => Traversable (ListT f) where
        traverse :: forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> ListT f a -> f (ListT f b)
    traverse a -> f b
    f (ListT f [a]
    a) = f [b] -> ListT f b
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (f [b] -> ListT f b) -> f (f [b]) -> f (ListT f b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ([a] -> f [b]) -> f [a] -> f (f [b])
    forall (t :: * -> *) (f :: * -> *) a b.
    (Traversable t, Applicative f) =>
    (a -> f b) -> t a -> f (t b)
    forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> f a -> f (f b)
    traverse ((a -> f b) -> [a] -> f [b]
    forall (t :: * -> *) (f :: * -> *) a b.
    (Traversable t, Applicative f) =>
    (a -> f b) -> t a -> f (t b)
    forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> [a] -> f [b]
    traverse a -> f b
    f) f [a]
    a
        {-# INLINE traverse #-}

    instance (Applicative m) => Applicative (ListT m) where
        pure :: forall a. a -> ListT m a
    pure a
    a  = m [a] -> ListT m a
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (m [a] -> ListT m a) -> m [a] -> ListT m a
    forall a b. (a -> b) -> a -> b
    $ [a] -> m [a]
    forall a. a -> m a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure [a
    a]
        {-# INLINE pure #-}
        ListT m (a -> b)
    f <*> :: forall a b. ListT m (a -> b) -> ListT m a -> ListT m b
    <*> ListT m a
    v = m [b] -> ListT m b
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (m [b] -> ListT m b) -> m [b] -> ListT m b
    forall a b. (a -> b) -> a -> b
    $ [a -> b] -> [a] -> [b]
    forall a b. [a -> b] -> [a] -> [b]
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    (<*>) ([a -> b] -> [a] -> [b]) -> m [a -> b] -> m ([a] -> [b])
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ListT m (a -> b) -> m [a -> b]
    forall (m :: * -> *) a. ListT m a -> m [a]
    runListT ListT m (a -> b)
    f m ([a] -> [b]) -> m [a] -> m [b]
    forall a b. m (a -> b) -> m a -> m b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> ListT m a -> m [a]
    forall (m :: * -> *) a. ListT m a -> m [a]
    runListT ListT m a
    v
        {-# INLINE (<*>) #-}

    instance (Applicative m) => Alternative (ListT m) where
        empty :: forall a. ListT m a
    empty   = m [a] -> ListT m a
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (m [a] -> ListT m a) -> m [a] -> ListT m a
    forall a b. (a -> b) -> a -> b
    $ [a] -> m [a]
    forall a. a -> m a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure []
        {-# INLINE empty #-}
        ListT m a
    m <|> :: forall a. ListT m a -> ListT m a -> ListT m a
    <|> ListT m a
    n = m [a] -> ListT m a
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (m [a] -> ListT m a) -> m [a] -> ListT m a
    forall a b. (a -> b) -> a -> b
    $ [a] -> [a] -> [a]
    forall a. [a] -> [a] -> [a]
    (++) ([a] -> [a] -> [a]) -> m [a] -> m ([a] -> [a])
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ListT m a -> m [a]
    forall (m :: * -> *) a. ListT m a -> m [a]
    runListT ListT m a
    m m ([a] -> [a]) -> m [a] -> m [a]
    forall a b. m (a -> b) -> m a -> m b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> ListT m a -> m [a]
    forall (m :: * -> *) a. ListT m a -> m [a]
    runListT ListT m a
    n
        {-# INLINE (<|>) #-}

    instance (Monad m) => Monad (ListT m) where
    #if !(MIN_VERSION_base(4,8,0))
        return a = ListT $ return [a]
        {-# INLINE return #-}
    #endif
        ListT m a
    m >>= :: forall a b. ListT m a -> (a -> ListT m b) -> ListT m b
    >>= a -> ListT m b
    k  = m [b] -> ListT m b
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (m [b] -> ListT m b) -> m [b] -> ListT m b
    forall a b. (a -> b) -> a -> b
    $ do
            [a]
    a <- ListT m a -> m [a]
    forall (m :: * -> *) a. ListT m a -> m [a]
    runListT ListT m a
    m
            [[b]]
    b <- (a -> m [b]) -> [a] -> m [[b]]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM (ListT m b -> m [b]
    forall (m :: * -> *) a. ListT m a -> m [a]
    runListT (ListT m b -> m [b]) -> (a -> ListT m b) -> a -> m [b]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> ListT m b
    k) [a]
    a
            [b] -> m [b]
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([[b]] -> [b]
    forall (t :: * -> *) a. Foldable t => t [a] -> [a]
    concat [[b]]
    b)
        {-# INLINE (>>=) #-}
    #if !(MIN_VERSION_base(4,13,0))
        fail _ = ListT $ return []
        {-# INLINE fail #-}
    #endif

    #if MIN_VERSION_base(4,9,0)
    instance (Monad m) => Fail.MonadFail (ListT m) where
        fail :: forall a. String -> ListT m a
    fail String
    _ = m [a] -> ListT m a
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (m [a] -> ListT m a) -> m [a] -> ListT m a
    forall a b. (a -> b) -> a -> b
    $ [a] -> m [a]
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return []
        {-# INLINE fail #-}
    #endif

    instance (Monad m) => MonadPlus (ListT m) where
        mzero :: forall a. ListT m a
    mzero       = m [a] -> ListT m a
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (m [a] -> ListT m a) -> m [a] -> ListT m a
    forall a b. (a -> b) -> a -> b
    $ [a] -> m [a]
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return []
        {-# INLINE mzero #-}
        ListT m a
    m mplus :: forall a. ListT m a -> ListT m a -> ListT m a
    `mplus` ListT m a
    n = m [a] -> ListT m a
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (m [a] -> ListT m a) -> m [a] -> ListT m a
    forall a b. (a -> b) -> a -> b
    $ do
            [a]
    a <- ListT m a -> m [a]
    forall (m :: * -> *) a. ListT m a -> m [a]
    runListT ListT m a
    m
            [a]
    b <- ListT m a -> m [a]
    forall (m :: * -> *) a. ListT m a -> m [a]
    runListT ListT m a
    n
            [a] -> m [a]
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([a]
    a [a] -> [a] -> [a]
    forall a. [a] -> [a] -> [a]
    ++ [a]
    b)
        {-# INLINE mplus #-}

    instance (MonadFix m) => MonadFix (ListT m) where
        mfix :: forall a. (a -> ListT m a) -> ListT m a
    mfix a -> ListT m a
    f = m [a] -> ListT m a
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (m [a] -> ListT m a) -> m [a] -> ListT m a
    forall a b. (a -> b) -> a -> b
    $ ([a] -> m [a]) -> m [a]
    forall a. (a -> m a) -> m a
    forall (m :: * -> *) a. MonadFix m => (a -> m a) -> m a
    mfix (ListT m a -> m [a]
    forall (m :: * -> *) a. ListT m a -> m [a]
    runListT (ListT m a -> m [a]) -> ([a] -> ListT m a) -> [a] -> m [a]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> ListT m a
    f (a -> ListT m a) -> ([a] -> a) -> [a] -> ListT m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [a] -> a
    forall a. HasCallStack => [a] -> a
    head) m [a] -> ([a] -> m [a]) -> m [a]
    forall a b. m a -> (a -> m b) -> m b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \ [a]
    xs -> case [a]
    xs of
            [] -> [a] -> m [a]
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return []
            a
    x:[a]
    _ -> ([a] -> [a]) -> m [a] -> m [a]
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM (a
    xa -> [a] -> [a]
    forall a. a -> [a] -> [a]
    :) (ListT m a -> m [a]
    forall (m :: * -> *) a. ListT m a -> m [a]
    runListT ((a -> ListT m a) -> ListT m a
    forall a. (a -> ListT m a) -> ListT m a
    forall (m :: * -> *) a. MonadFix m => (a -> m a) -> m a
    mfix ((m [a] -> m [a]) -> ListT m a -> ListT m a
    forall (m :: * -> *) a (n :: * -> *) b.
    (m [a] -> n [b]) -> ListT m a -> ListT n b
    mapListT (([a] -> [a]) -> m [a] -> m [a]
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM [a] -> [a]
    forall a. HasCallStack => [a] -> [a]
    tail) (ListT m a -> ListT m a) -> (a -> ListT m a) -> a -> ListT m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> ListT m a
    f)))
        {-# INLINE mfix #-}

    instance MonadTrans ListT where
        lift :: forall (m :: * -> *) a. Monad m => m a -> ListT m a
    lift m a
    m = m [a] -> ListT m a
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (m [a] -> ListT m a) -> m [a] -> ListT m a
    forall a b. (a -> b) -> a -> b
    $ do
            a
    a <- m a
    m
            [a] -> m [a]
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return [a
    a]
        {-# INLINE lift #-}

    instance (MonadIO m) => MonadIO (ListT m) where
        liftIO :: forall a. IO a -> ListT m a
    liftIO = m a -> ListT m a
    forall (m :: * -> *) a. Monad m => m a -> ListT m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m a -> ListT m a) -> (IO a -> m a) -> IO a -> ListT 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
        {-# INLINE liftIO #-}

    #if MIN_VERSION_base(4,4,0)
    instance (MonadZip m) => MonadZip (ListT m) where
        mzipWith :: forall a b c. (a -> b -> c) -> ListT m a -> ListT m b -> ListT m c
    mzipWith a -> b -> c
    f (ListT m [a]
    a) (ListT m [b]
    b) = m [c] -> ListT m c
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (m [c] -> ListT m c) -> m [c] -> ListT m c
    forall a b. (a -> b) -> a -> b
    $ ([a] -> [b] -> [c]) -> m [a] -> m [b] -> m [c]
    forall a b c. (a -> b -> c) -> m a -> m b -> m c
    forall (m :: * -> *) a b c.
    MonadZip m =>
    (a -> b -> c) -> m a -> m b -> m c
    mzipWith ((a -> b -> c) -> [a] -> [b] -> [c]
    forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
    zipWith a -> b -> c
    f) m [a]
    a m [b]
    b
        {-# INLINE mzipWith #-}
    #endif

    #if MIN_VERSION_base(4,12,0)
    instance Contravariant m => Contravariant (ListT m) where
        contramap :: forall a' a. (a' -> a) -> ListT m a -> ListT m a'
    contramap a' -> a
    f = m [a'] -> ListT m a'
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (m [a'] -> ListT m a')
    -> (ListT m a -> m [a']) -> ListT m a -> ListT m a'
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ([a'] -> [a]) -> m [a] -> m [a']
    forall a' a. (a' -> a) -> m a -> m a'
    forall (f :: * -> *) a' a.
    Contravariant f =>
    (a' -> a) -> f a -> f a'
    contramap ((a' -> a) -> [a'] -> [a]
    forall a b. (a -> b) -> [a] -> [b]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap a' -> a
    f) (m [a] -> m [a']) -> (ListT m a -> m [a]) -> ListT m a -> m [a']
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ListT m a -> m [a]
    forall (m :: * -> *) a. ListT m a -> m [a]
    runListT
        {-# INLINE contramap #-}
    #endif

    -- | Lift a @callCC@ operation to the new monad.
    liftCallCC :: CallCC m [a] [b] -> CallCC (ListT m) a b
    liftCallCC :: forall (m :: * -> *) a b. CallCC m [a] [b] -> CallCC (ListT m) a b
    liftCallCC CallCC m [a] [b]
    callCC (a -> ListT m b) -> ListT m a
    f = m [a] -> ListT m a
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (m [a] -> ListT m a) -> m [a] -> ListT m a
    forall a b. (a -> b) -> a -> b
    $
        CallCC m [a] [b]
    callCC CallCC m [a] [b] -> CallCC m [a] [b]
    forall a b. (a -> b) -> a -> b
    $ \ [a] -> m [b]
    c ->
        ListT m a -> m [a]
    forall (m :: * -> *) a. ListT m a -> m [a]
    runListT ((a -> ListT m b) -> ListT m a
    f (\ a
    a -> m [b] -> ListT m b
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (m [b] -> ListT m b) -> m [b] -> ListT m b
    forall a b. (a -> b) -> a -> b
    $ [a] -> m [b]
    c [a
    a]))
    {-# INLINE liftCallCC #-}

    -- | Lift a @catchE@ operation to the new monad.
    liftCatch :: Catch e m [a] -> Catch e (ListT m) a
    liftCatch :: forall e (m :: * -> *) a. Catch e m [a] -> Catch e (ListT m) a
    liftCatch Catch e m [a]
    catchE ListT m a
    m e -> ListT m a
    h = m [a] -> ListT m a
    forall (m :: * -> *) a. m [a] -> ListT m a
    ListT (m [a] -> ListT m a) -> m [a] -> ListT m a
    forall a b. (a -> b) -> a -> b
    $ ListT m a -> m [a]
    forall (m :: * -> *) a. ListT m a -> m [a]
    runListT ListT m a
    m
        Catch e m [a]
    `catchE` \ e
    e -> ListT m a -> m [a]
    forall (m :: * -> *) a. ListT m a -> m [a]
    runListT (e -> ListT m a
    h e
    e)
    {-# INLINE liftCatch #-}