{-# LANGUAGE UndecidableInstances #-}

--------------------------------------------------------------------------------
-- |
-- Module      : Control.Monad.Heap.List
-- Copyright   : (c) Donnacha Oisín Kidney 2021
-- Maintainer  : mail@doisinkidney.com
-- Stability   : experimental
-- Portability : non-portable
--
-- A simple re-implementation of the list monad transformer, for use by the heap
-- monad.
--------------------------------------------------------------------------------
module Control.Monad.Heap.List
  ( -- * Type Definition
    ListT(..)
  , ListCons(..)
    -- * Building the list
  , unfoldrM
  , cons
  , nil
  , fromListT
    -- * Running the list
  , toListT
  , foldListT
    -- * Transforming lists
  , catMaybesT
  , listMmap
  , scanl1M
  ) where

import Data.Bifunctor ( Bifunctor(first, bimap) )
import Data.Bifoldable ( Bifoldable(..) , bifoldl', bifoldr')
import Data.Bitraversable ( Bitraversable(..) )
import Control.Monad ( MonadPlus )
import Control.Applicative
    ( Applicative(liftA2), Alternative((<|>), empty) )
import Control.Monad.Trans ( MonadTrans(..) )
import Control.Monad.State ( MonadState(..) )
import Control.Monad.Except ( MonadError(..) )
import Control.Monad.Reader ( MonadReader(..) )
import Control.Monad.Writer ( MonadWriter(..) )
import Data.Monoid (Alt(Alt))
import Control.Monad.Cont ( MonadCont(..) )
import Test.QuickCheck
    ( Arbitrary(..),
      arbitrary1,
      arbitrary2,
      shrink1,
      shrink2,
      frequency,
      sized,
      Arbitrary1(..),
      Arbitrary2(..) )
import MonusWeightedSearch.Internal.CoerceOperators
    ( (#.), (.#), (<#$>) )
import Control.DeepSeq ( NFData(..) )
import GHC.Generics ( Generic, Generic1 )
import Data.Data ( Data, Typeable )
import Data.Foldable ( Foldable(foldr', foldl') )
import Text.Read (readPrec, parens, prec, Lexeme(Ident), lexP, step)
import GHC.Exts (IsList)
import qualified GHC.Exts as IsList
import Data.List (unfoldr)
import Data.Functor.Identity (Identity(..))
import Data.Coerce (coerce)

infixr 5 :-
-- | The list constructor.
data ListCons a b = Nil | a :- !b
  deriving ((forall a b. (a -> b) -> ListCons a a -> ListCons a b)
-> (forall a b. a -> ListCons a b -> ListCons a a)
-> Functor (ListCons a)
forall a b. a -> ListCons a b -> ListCons a a
forall a b. (a -> b) -> ListCons a a -> ListCons a b
forall a a b. a -> ListCons a b -> ListCons a a
forall a a b. (a -> b) -> ListCons a a -> ListCons a b
forall (f :: Type -> Type).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> ListCons a b -> ListCons a a
$c<$ :: forall a a b. a -> ListCons a b -> ListCons a a
fmap :: forall a b. (a -> b) -> ListCons a a -> ListCons a b
$cfmap :: forall a a b. (a -> b) -> ListCons a a -> ListCons a b
Functor, (forall m. Monoid m => ListCons a m -> m)
-> (forall m a. Monoid m => (a -> m) -> ListCons a a -> m)
-> (forall m a. Monoid m => (a -> m) -> ListCons a a -> m)
-> (forall a b. (a -> b -> b) -> b -> ListCons a a -> b)
-> (forall a b. (a -> b -> b) -> b -> ListCons a a -> b)
-> (forall b a. (b -> a -> b) -> b -> ListCons a a -> b)
-> (forall b a. (b -> a -> b) -> b -> ListCons a a -> b)
-> (forall a. (a -> a -> a) -> ListCons a a -> a)
-> (forall a. (a -> a -> a) -> ListCons a a -> a)
-> (forall a. ListCons a a -> [a])
-> (forall a. ListCons a a -> Bool)
-> (forall a. ListCons a a -> Int)
-> (forall a. Eq a => a -> ListCons a a -> Bool)
-> (forall a. Ord a => ListCons a a -> a)
-> (forall a. Ord a => ListCons a a -> a)
-> (forall a. Num a => ListCons a a -> a)
-> (forall a. Num a => ListCons a a -> a)
-> Foldable (ListCons a)
forall a. Eq a => a -> ListCons a a -> Bool
forall a. Num a => ListCons a a -> a
forall a. Ord a => ListCons a a -> a
forall m. Monoid m => ListCons a m -> m
forall a. ListCons a a -> Bool
forall a. ListCons a a -> Int
forall a. ListCons a a -> [a]
forall a. (a -> a -> a) -> ListCons a a -> a
forall a a. Eq a => a -> ListCons a a -> Bool
forall a a. Num a => ListCons a a -> a
forall a a. Ord a => ListCons a a -> a
forall m a. Monoid m => (a -> m) -> ListCons a a -> m
forall a m. Monoid m => ListCons a m -> m
forall a a. ListCons a a -> Bool
forall a a. ListCons a a -> Int
forall a a. ListCons a a -> [a]
forall b a. (b -> a -> b) -> b -> ListCons a a -> b
forall a b. (a -> b -> b) -> b -> ListCons a a -> b
forall a a. (a -> a -> a) -> ListCons a a -> a
forall a m a. Monoid m => (a -> m) -> ListCons a a -> m
forall a b a. (b -> a -> b) -> b -> ListCons a a -> b
forall a a b. (a -> b -> b) -> b -> ListCons a a -> b
forall (t :: Type -> Type).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => ListCons a a -> a
$cproduct :: forall a a. Num a => ListCons a a -> a
sum :: forall a. Num a => ListCons a a -> a
$csum :: forall a a. Num a => ListCons a a -> a
minimum :: forall a. Ord a => ListCons a a -> a
$cminimum :: forall a a. Ord a => ListCons a a -> a
maximum :: forall a. Ord a => ListCons a a -> a
$cmaximum :: forall a a. Ord a => ListCons a a -> a
elem :: forall a. Eq a => a -> ListCons a a -> Bool
$celem :: forall a a. Eq a => a -> ListCons a a -> Bool
length :: forall a. ListCons a a -> Int
$clength :: forall a a. ListCons a a -> Int
null :: forall a. ListCons a a -> Bool
$cnull :: forall a a. ListCons a a -> Bool
toList :: forall a. ListCons a a -> [a]
$ctoList :: forall a a. ListCons a a -> [a]
foldl1 :: forall a. (a -> a -> a) -> ListCons a a -> a
$cfoldl1 :: forall a a. (a -> a -> a) -> ListCons a a -> a
foldr1 :: forall a. (a -> a -> a) -> ListCons a a -> a
$cfoldr1 :: forall a a. (a -> a -> a) -> ListCons a a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> ListCons a a -> b
$cfoldl' :: forall a b a. (b -> a -> b) -> b -> ListCons a a -> b
foldl :: forall b a. (b -> a -> b) -> b -> ListCons a a -> b
$cfoldl :: forall a b a. (b -> a -> b) -> b -> ListCons a a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> ListCons a a -> b
$cfoldr' :: forall a a b. (a -> b -> b) -> b -> ListCons a a -> b
foldr :: forall a b. (a -> b -> b) -> b -> ListCons a a -> b
$cfoldr :: forall a a b. (a -> b -> b) -> b -> ListCons a a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> ListCons a a -> m
$cfoldMap' :: forall a m a. Monoid m => (a -> m) -> ListCons a a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> ListCons a a -> m
$cfoldMap :: forall a m a. Monoid m => (a -> m) -> ListCons a a -> m
fold :: forall m. Monoid m => ListCons a m -> m
$cfold :: forall a m. Monoid m => ListCons a m -> m
Foldable, Functor (ListCons a)
Foldable (ListCons a)
Functor (ListCons a)
-> Foldable (ListCons a)
-> (forall (f :: Type -> Type) a b.
    Applicative f =>
    (a -> f b) -> ListCons a a -> f (ListCons a b))
-> (forall (f :: Type -> Type) a.
    Applicative f =>
    ListCons a (f a) -> f (ListCons a a))
-> (forall (m :: Type -> Type) a b.
    Monad m =>
    (a -> m b) -> ListCons a a -> m (ListCons a b))
-> (forall (m :: Type -> Type) a.
    Monad m =>
    ListCons a (m a) -> m (ListCons a a))
-> Traversable (ListCons a)
forall a. Functor (ListCons a)
forall a. Foldable (ListCons a)
forall a (m :: Type -> Type) a.
Monad m =>
ListCons a (m a) -> m (ListCons a a)
forall a (f :: Type -> Type) a.
Applicative f =>
ListCons a (f a) -> f (ListCons a a)
forall a (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> ListCons a a -> m (ListCons a b)
forall a (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> ListCons a a -> f (ListCons a b)
forall (t :: Type -> Type).
Functor t
-> Foldable t
-> (forall (f :: Type -> Type) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: Type -> Type) a.
    Applicative f =>
    t (f a) -> f (t a))
-> (forall (m :: Type -> Type) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: Type -> Type) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: Type -> Type) a.
Monad m =>
ListCons a (m a) -> m (ListCons a a)
forall (f :: Type -> Type) a.
Applicative f =>
ListCons a (f a) -> f (ListCons a a)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> ListCons a a -> m (ListCons a b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> ListCons a a -> f (ListCons a b)
sequence :: forall (m :: Type -> Type) a.
Monad m =>
ListCons a (m a) -> m (ListCons a a)
$csequence :: forall a (m :: Type -> Type) a.
Monad m =>
ListCons a (m a) -> m (ListCons a a)
mapM :: forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> ListCons a a -> m (ListCons a b)
$cmapM :: forall a (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> ListCons a a -> m (ListCons a b)
sequenceA :: forall (f :: Type -> Type) a.
Applicative f =>
ListCons a (f a) -> f (ListCons a a)
$csequenceA :: forall a (f :: Type -> Type) a.
Applicative f =>
ListCons a (f a) -> f (ListCons a a)
traverse :: forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> ListCons a a -> f (ListCons a b)
$ctraverse :: forall a (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> ListCons a a -> f (ListCons a b)
Traversable, ListCons a b -> ListCons a b -> Bool
(ListCons a b -> ListCons a b -> Bool)
-> (ListCons a b -> ListCons a b -> Bool) -> Eq (ListCons a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b. (Eq a, Eq b) => ListCons a b -> ListCons a b -> Bool
/= :: ListCons a b -> ListCons a b -> Bool
$c/= :: forall a b. (Eq a, Eq b) => ListCons a b -> ListCons a b -> Bool
== :: ListCons a b -> ListCons a b -> Bool
$c== :: forall a b. (Eq a, Eq b) => ListCons a b -> ListCons a b -> Bool
Eq, Eq (ListCons a b)
Eq (ListCons a b)
-> (ListCons a b -> ListCons a b -> Ordering)
-> (ListCons a b -> ListCons a b -> Bool)
-> (ListCons a b -> ListCons a b -> Bool)
-> (ListCons a b -> ListCons a b -> Bool)
-> (ListCons a b -> ListCons a b -> Bool)
-> (ListCons a b -> ListCons a b -> ListCons a b)
-> (ListCons a b -> ListCons a b -> ListCons a b)
-> Ord (ListCons a b)
ListCons a b -> ListCons a b -> Bool
ListCons a b -> ListCons a b -> Ordering
ListCons a b -> ListCons a b -> ListCons a b
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 {a} {b}. (Ord a, Ord b) => Eq (ListCons a b)
forall a b. (Ord a, Ord b) => ListCons a b -> ListCons a b -> Bool
forall a b.
(Ord a, Ord b) =>
ListCons a b -> ListCons a b -> Ordering
forall a b.
(Ord a, Ord b) =>
ListCons a b -> ListCons a b -> ListCons a b
min :: ListCons a b -> ListCons a b -> ListCons a b
$cmin :: forall a b.
(Ord a, Ord b) =>
ListCons a b -> ListCons a b -> ListCons a b
max :: ListCons a b -> ListCons a b -> ListCons a b
$cmax :: forall a b.
(Ord a, Ord b) =>
ListCons a b -> ListCons a b -> ListCons a b
>= :: ListCons a b -> ListCons a b -> Bool
$c>= :: forall a b. (Ord a, Ord b) => ListCons a b -> ListCons a b -> Bool
> :: ListCons a b -> ListCons a b -> Bool
$c> :: forall a b. (Ord a, Ord b) => ListCons a b -> ListCons a b -> Bool
<= :: ListCons a b -> ListCons a b -> Bool
$c<= :: forall a b. (Ord a, Ord b) => ListCons a b -> ListCons a b -> Bool
< :: ListCons a b -> ListCons a b -> Bool
$c< :: forall a b. (Ord a, Ord b) => ListCons a b -> ListCons a b -> Bool
compare :: ListCons a b -> ListCons a b -> Ordering
$ccompare :: forall a b.
(Ord a, Ord b) =>
ListCons a b -> ListCons a b -> Ordering
Ord, Int -> ListCons a b -> ShowS
[ListCons a b] -> ShowS
ListCons a b -> String
(Int -> ListCons a b -> ShowS)
-> (ListCons a b -> String)
-> ([ListCons a b] -> ShowS)
-> Show (ListCons a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. (Show a, Show b) => Int -> ListCons a b -> ShowS
forall a b. (Show a, Show b) => [ListCons a b] -> ShowS
forall a b. (Show a, Show b) => ListCons a b -> String
showList :: [ListCons a b] -> ShowS
$cshowList :: forall a b. (Show a, Show b) => [ListCons a b] -> ShowS
show :: ListCons a b -> String
$cshow :: forall a b. (Show a, Show b) => ListCons a b -> String
showsPrec :: Int -> ListCons a b -> ShowS
$cshowsPrec :: forall a b. (Show a, Show b) => Int -> ListCons a b -> ShowS
Show, ReadPrec [ListCons a b]
ReadPrec (ListCons a b)
Int -> ReadS (ListCons a b)
ReadS [ListCons a b]
(Int -> ReadS (ListCons a b))
-> ReadS [ListCons a b]
-> ReadPrec (ListCons a b)
-> ReadPrec [ListCons a b]
-> Read (ListCons a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall a b. (Read a, Read b) => ReadPrec [ListCons a b]
forall a b. (Read a, Read b) => ReadPrec (ListCons a b)
forall a b. (Read a, Read b) => Int -> ReadS (ListCons a b)
forall a b. (Read a, Read b) => ReadS [ListCons a b]
readListPrec :: ReadPrec [ListCons a b]
$creadListPrec :: forall a b. (Read a, Read b) => ReadPrec [ListCons a b]
readPrec :: ReadPrec (ListCons a b)
$creadPrec :: forall a b. (Read a, Read b) => ReadPrec (ListCons a b)
readList :: ReadS [ListCons a b]
$creadList :: forall a b. (Read a, Read b) => ReadS [ListCons a b]
readsPrec :: Int -> ReadS (ListCons a b)
$creadsPrec :: forall a b. (Read a, Read b) => Int -> ReadS (ListCons a b)
Read, Typeable (ListCons a b)
Typeable (ListCons a b)
-> (forall (c :: Type -> Type).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ListCons a b -> c (ListCons a b))
-> (forall (c :: Type -> Type).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (ListCons a b))
-> (ListCons a b -> Constr)
-> (ListCons a b -> DataType)
-> (forall (t :: Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (ListCons a b)))
-> (forall (t :: Type -> Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (ListCons a b)))
-> ((forall b. Data b => b -> b) -> ListCons a b -> ListCons a b)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ListCons a b -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ListCons a b -> r)
-> (forall u. (forall d. Data d => d -> u) -> ListCons a b -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ListCons a b -> u)
-> (forall (m :: Type -> Type).
    Monad m =>
    (forall d. Data d => d -> m d) -> ListCons a b -> m (ListCons a b))
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ListCons a b -> m (ListCons a b))
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ListCons a b -> m (ListCons a b))
-> Data (ListCons a b)
ListCons a b -> DataType
ListCons a b -> Constr
(forall b. Data b => b -> b) -> ListCons a b -> ListCons a b
forall a.
Typeable a
-> (forall (c :: Type -> Type).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: Type -> Type).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: Type -> Type -> Type) (c :: Type -> Type).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: Type -> Type).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: Type -> Type).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ListCons a b -> u
forall u. (forall d. Data d => d -> u) -> ListCons a b -> [u]
forall {a} {b}. (Data a, Data b) => Typeable (ListCons a b)
forall a b. (Data a, Data b) => ListCons a b -> DataType
forall a b. (Data a, Data b) => ListCons a b -> Constr
forall a b.
(Data a, Data b) =>
(forall b. Data b => b -> b) -> ListCons a b -> ListCons a b
forall a b u.
(Data a, Data b) =>
Int -> (forall d. Data d => d -> u) -> ListCons a b -> u
forall a b u.
(Data a, Data b) =>
(forall d. Data d => d -> u) -> ListCons a b -> [u]
forall a b r r'.
(Data a, Data b) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ListCons a b -> r
forall a b r r'.
(Data a, Data b) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ListCons a b -> r
forall a b (m :: Type -> Type).
(Data a, Data b, Monad m) =>
(forall d. Data d => d -> m d) -> ListCons a b -> m (ListCons a b)
forall a b (m :: Type -> Type).
(Data a, Data b, MonadPlus m) =>
(forall d. Data d => d -> m d) -> ListCons a b -> m (ListCons a b)
forall a b (c :: Type -> Type).
(Data a, Data b) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ListCons a b)
forall a b (c :: Type -> Type).
(Data a, Data b) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ListCons a b -> c (ListCons a b)
forall a b (t :: Type -> Type) (c :: Type -> Type).
(Data a, Data b, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (ListCons a b))
forall a b (t :: Type -> Type -> Type) (c :: Type -> Type).
(Data a, Data b, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ListCons a b))
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ListCons a b -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ListCons a b -> r
forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> ListCons a b -> m (ListCons a b)
forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ListCons a b -> m (ListCons a b)
forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ListCons a b)
forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ListCons a b -> c (ListCons a b)
forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (ListCons a b))
forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ListCons a b))
gmapMo :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ListCons a b -> m (ListCons a b)
$cgmapMo :: forall a b (m :: Type -> Type).
(Data a, Data b, MonadPlus m) =>
(forall d. Data d => d -> m d) -> ListCons a b -> m (ListCons a b)
gmapMp :: forall (m :: Type -> Type).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ListCons a b -> m (ListCons a b)
$cgmapMp :: forall a b (m :: Type -> Type).
(Data a, Data b, MonadPlus m) =>
(forall d. Data d => d -> m d) -> ListCons a b -> m (ListCons a b)
gmapM :: forall (m :: Type -> Type).
Monad m =>
(forall d. Data d => d -> m d) -> ListCons a b -> m (ListCons a b)
$cgmapM :: forall a b (m :: Type -> Type).
(Data a, Data b, Monad m) =>
(forall d. Data d => d -> m d) -> ListCons a b -> m (ListCons a b)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ListCons a b -> u
$cgmapQi :: forall a b u.
(Data a, Data b) =>
Int -> (forall d. Data d => d -> u) -> ListCons a b -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> ListCons a b -> [u]
$cgmapQ :: forall a b u.
(Data a, Data b) =>
(forall d. Data d => d -> u) -> ListCons a b -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ListCons a b -> r
$cgmapQr :: forall a b r r'.
(Data a, Data b) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ListCons a b -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ListCons a b -> r
$cgmapQl :: forall a b r r'.
(Data a, Data b) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ListCons a b -> r
gmapT :: (forall b. Data b => b -> b) -> ListCons a b -> ListCons a b
$cgmapT :: forall a b.
(Data a, Data b) =>
(forall b. Data b => b -> b) -> ListCons a b -> ListCons a b
dataCast2 :: forall (t :: Type -> Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ListCons a b))
$cdataCast2 :: forall a b (t :: Type -> Type -> Type) (c :: Type -> Type).
(Data a, Data b, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ListCons a b))
dataCast1 :: forall (t :: Type -> Type) (c :: Type -> Type).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (ListCons a b))
$cdataCast1 :: forall a b (t :: Type -> Type) (c :: Type -> Type).
(Data a, Data b, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (ListCons a b))
dataTypeOf :: ListCons a b -> DataType
$cdataTypeOf :: forall a b. (Data a, Data b) => ListCons a b -> DataType
toConstr :: ListCons a b -> Constr
$ctoConstr :: forall a b. (Data a, Data b) => ListCons a b -> Constr
gunfold :: forall (c :: Type -> Type).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ListCons a b)
$cgunfold :: forall a b (c :: Type -> Type).
(Data a, Data b) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ListCons a b)
gfoldl :: forall (c :: Type -> Type).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ListCons a b -> c (ListCons a b)
$cgfoldl :: forall a b (c :: Type -> Type).
(Data a, Data b) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ListCons a b -> c (ListCons a b)
Data, Typeable, (forall x. ListCons a b -> Rep (ListCons a b) x)
-> (forall x. Rep (ListCons a b) x -> ListCons a b)
-> Generic (ListCons a b)
forall x. Rep (ListCons a b) x -> ListCons a b
forall x. ListCons a b -> Rep (ListCons a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (ListCons a b) x -> ListCons a b
forall a b x. ListCons a b -> Rep (ListCons a b) x
$cto :: forall a b x. Rep (ListCons a b) x -> ListCons a b
$cfrom :: forall a b x. ListCons a b -> Rep (ListCons a b) x
Generic, (forall a. ListCons a a -> Rep1 (ListCons a) a)
-> (forall a. Rep1 (ListCons a) a -> ListCons a a)
-> Generic1 (ListCons a)
forall a. Rep1 (ListCons a) a -> ListCons a a
forall a. ListCons a a -> Rep1 (ListCons a) a
forall a a. Rep1 (ListCons a) a -> ListCons a a
forall a a. ListCons a a -> Rep1 (ListCons a) a
forall k (f :: k -> Type).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cto1 :: forall a a. Rep1 (ListCons a) a -> ListCons a a
$cfrom1 :: forall a a. ListCons a a -> Rep1 (ListCons a) a
Generic1)

instance (NFData a, NFData b) => NFData (ListCons a b) where
  rnf :: ListCons a b -> ()
rnf ListCons a b
Nil = ()
  rnf (a
x :- b
xs) = a -> ()
forall a. NFData a => a -> ()
rnf a
x () -> () -> ()
`seq` b -> ()
forall a. NFData a => a -> ()
rnf b
xs
  {-# INLINE rnf #-}

instance Bifunctor ListCons where
  bimap :: forall a b c d.
(a -> b) -> (c -> d) -> ListCons a c -> ListCons b d
bimap a -> b
f c -> d
g ListCons a c
Nil = ListCons b d
forall a b. ListCons a b
Nil
  bimap a -> b
f c -> d
g (a
x :- c
xs) = a -> b
f a
x b -> d -> ListCons b d
forall a b. a -> b -> ListCons a b
:- c -> d
g c
xs
  {-# INLINE bimap #-}

instance Bifoldable ListCons where
  bifold :: forall m. Monoid m => ListCons m m -> m
bifold ListCons m m
Nil = m
forall a. Monoid a => a
mempty
  bifold (m
x :- m
xs) = m
x m -> m -> m
forall a. Semigroup a => a -> a -> a
<> m
xs
  {-# INLINE bifold #-}

  bifoldMap :: forall m a b. Monoid m => (a -> m) -> (b -> m) -> ListCons a b -> m
bifoldMap a -> m
f b -> m
g ListCons a b
Nil = m
forall a. Monoid a => a
mempty
  bifoldMap a -> m
f b -> m
g (a
x :- b
xs) = a -> m
f a
x m -> m -> m
forall a. Semigroup a => a -> a -> a
<> b -> m
g b
xs
  {-# INLINE bifoldMap #-}

  bifoldr :: forall a c b.
(a -> c -> c) -> (b -> c -> c) -> c -> ListCons a b -> c
bifoldr a -> c -> c
f b -> c -> c
g c
b ListCons a b
Nil = c
b
  bifoldr a -> c -> c
f b -> c -> c
g c
b (a
x :- b
xs) = a -> c -> c
f a
x (b -> c -> c
g b
xs c
b)
  {-# INLINE bifoldr #-}

  bifoldl :: forall c a b.
(c -> a -> c) -> (c -> b -> c) -> c -> ListCons a b -> c
bifoldl c -> a -> c
f c -> b -> c
g c
b ListCons a b
Nil = c
b
  bifoldl c -> a -> c
f c -> b -> c
g c
b (a
x :- b
xs) = c -> b -> c
g (c -> a -> c
f c
b a
x) b
xs
  {-# INLINE bifoldl #-}
  
instance Bitraversable ListCons where
  bitraverse :: forall (f :: Type -> Type) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> ListCons a b -> f (ListCons c d)
bitraverse a -> f c
f b -> f d
g ListCons a b
Nil = ListCons c d -> f (ListCons c d)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure ListCons c d
forall a b. ListCons a b
Nil
  bitraverse a -> f c
f b -> f d
g (a
a :- b
b) = (c -> d -> ListCons c d) -> f c -> f d -> f (ListCons c d)
forall (f :: Type -> Type) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 c -> d -> ListCons c d
forall a b. a -> b -> ListCons a b
(:-) (a -> f c
f a
a) (b -> f d
g b
b)
  {-# INLINE bitraverse #-}

instance Arbitrary2 ListCons where
  liftArbitrary2 :: forall a b. Gen a -> Gen b -> Gen (ListCons a b)
liftArbitrary2 Gen a
xs Gen b
ys = (Int -> Gen (ListCons a b)) -> Gen (ListCons a b)
forall a. (Int -> Gen a) -> Gen a
sized (\Int
n -> [(Int, Gen (ListCons a b))] -> Gen (ListCons a b)
forall a. [(Int, Gen a)] -> Gen a
frequency ((Int
1, ListCons a b -> Gen (ListCons a b)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure ListCons a b
forall a b. ListCons a b
Nil) (Int, Gen (ListCons a b))
-> [(Int, Gen (ListCons a b))] -> [(Int, Gen (ListCons a b))]
forall a. a -> [a] -> [a]
: [(Int
n, (a -> b -> ListCons a b) -> Gen a -> Gen b -> Gen (ListCons a b)
forall (f :: Type -> Type) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> b -> ListCons a b
forall a b. a -> b -> ListCons a b
(:-) Gen a
xs Gen b
ys) | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
1]))
  liftShrink2 :: forall a b.
(a -> [a]) -> (b -> [b]) -> ListCons a b -> [ListCons a b]
liftShrink2 a -> [a]
xs b -> [b]
ys ListCons a b
Nil = []
  liftShrink2 a -> [a]
xs b -> [b]
ys (a
x :- b
y) = ListCons a b
forall a b. ListCons a b
Nil ListCons a b -> [ListCons a b] -> [ListCons a b]
forall a. a -> [a] -> [a]
: ((a, b) -> ListCons a b) -> [(a, b)] -> [ListCons a b]
forall a b. (a -> b) -> [a] -> [b]
map ((a -> b -> ListCons a b) -> (a, b) -> ListCons a b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> b -> ListCons a b
forall a b. a -> b -> ListCons a b
(:-)) ((a -> [a]) -> (b -> [b]) -> (a, b) -> [(a, b)]
forall (f :: Type -> Type -> Type) a b.
Arbitrary2 f =>
(a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
liftShrink2 a -> [a]
xs b -> [b]
ys (a
x,b
y))
  
instance Arbitrary a => Arbitrary1 (ListCons a) where
  liftArbitrary :: forall a. Gen a -> Gen (ListCons a a)
liftArbitrary = Gen a -> Gen a -> Gen (ListCons a a)
forall (f :: Type -> Type -> Type) a b.
Arbitrary2 f =>
Gen a -> Gen b -> Gen (f a b)
liftArbitrary2 Gen a
forall a. Arbitrary a => Gen a
arbitrary
  liftShrink :: forall a. (a -> [a]) -> ListCons a a -> [ListCons a a]
liftShrink = (a -> [a]) -> (a -> [a]) -> ListCons a a -> [ListCons a a]
forall (f :: Type -> Type -> Type) a b.
Arbitrary2 f =>
(a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
liftShrink2 a -> [a]
forall a. Arbitrary a => a -> [a]
shrink
  
instance (Arbitrary a, Arbitrary b) => Arbitrary (ListCons a b) where
  arbitrary :: Gen (ListCons a b)
arbitrary = Gen (ListCons a b)
forall (f :: Type -> Type -> Type) a b.
(Arbitrary2 f, Arbitrary a, Arbitrary b) =>
Gen (f a b)
arbitrary2
  shrink :: ListCons a b -> [ListCons a b]
shrink = ListCons a b -> [ListCons a b]
forall (f :: Type -> Type -> Type) a b.
(Arbitrary2 f, Arbitrary a, Arbitrary b) =>
f a b -> [f a b]
shrink2

-- | A list monad transformer, "done right".
newtype ListT m a
  = ListT { forall (m :: Type -> Type) a.
ListT m a -> m (ListCons a (ListT m a))
runListT :: m (ListCons a (ListT m a)) }
  deriving (Typeable, (forall x. ListT m a -> Rep (ListT m a) x)
-> (forall x. Rep (ListT m a) x -> ListT m a)
-> Generic (ListT m a)
forall x. Rep (ListT m a) x -> ListT m a
forall x. ListT m a -> Rep (ListT m a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (m :: Type -> Type) a x. Rep (ListT m a) x -> ListT m a
forall (m :: Type -> Type) a x. ListT m a -> Rep (ListT m a) x
$cto :: forall (m :: Type -> Type) a x. Rep (ListT m a) x -> ListT m a
$cfrom :: forall (m :: Type -> Type) a x. ListT m a -> Rep (ListT m a) x
Generic)
  deriving (NonEmpty (ListT m a) -> ListT m a
ListT m a -> ListT m a -> ListT m a
(ListT m a -> ListT m a -> ListT m a)
-> (NonEmpty (ListT m a) -> ListT m a)
-> (forall b. Integral b => b -> ListT m a -> ListT m a)
-> Semigroup (ListT m a)
forall b. Integral b => b -> ListT m a -> ListT m a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall (m :: Type -> Type) a.
Monad m =>
NonEmpty (ListT m a) -> ListT m a
forall (m :: Type -> Type) a.
Monad m =>
ListT m a -> ListT m a -> ListT m a
forall (m :: Type -> Type) a b.
(Monad m, Integral b) =>
b -> ListT m a -> ListT m a
stimes :: forall b. Integral b => b -> ListT m a -> ListT m a
$cstimes :: forall (m :: Type -> Type) a b.
(Monad m, Integral b) =>
b -> ListT m a -> ListT m a
sconcat :: NonEmpty (ListT m a) -> ListT m a
$csconcat :: forall (m :: Type -> Type) a.
Monad m =>
NonEmpty (ListT m a) -> ListT m a
<> :: ListT m a -> ListT m a -> ListT m a
$c<> :: forall (m :: Type -> Type) a.
Monad m =>
ListT m a -> ListT m a -> ListT m a
Semigroup, Semigroup (ListT m a)
ListT m a
Semigroup (ListT m a)
-> ListT m a
-> (ListT m a -> ListT m a -> ListT m a)
-> ([ListT m a] -> ListT m a)
-> Monoid (ListT m a)
[ListT m a] -> ListT m a
ListT m a -> ListT m a -> ListT m a
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall (m :: Type -> Type) a. Monad m => Semigroup (ListT m a)
forall (m :: Type -> Type) a. Monad m => ListT m a
forall (m :: Type -> Type) a. Monad m => [ListT m a] -> ListT m a
forall (m :: Type -> Type) a.
Monad m =>
ListT m a -> ListT m a -> ListT m a
mconcat :: [ListT m a] -> ListT m a
$cmconcat :: forall (m :: Type -> Type) a. Monad m => [ListT m a] -> ListT m a
mappend :: ListT m a -> ListT m a -> ListT m a
$cmappend :: forall (m :: Type -> Type) a.
Monad m =>
ListT m a -> ListT m a -> ListT m a
mempty :: ListT m a
$cmempty :: forall (m :: Type -> Type) a. Monad m => ListT m a
Monoid) via Alt (ListT m) a

deriving instance (forall x. Data x => Data (m x), Typeable m, Data a) => Data (ListT m a)

deriving newtype instance (forall x. NFData x => NFData (m x), NFData a) => NFData (ListT m a)

-- | Unfold, monadically, a list from a seed.
unfoldrM :: Functor m => (b -> m (Maybe (a, b))) -> b -> ListT m a
unfoldrM :: forall (m :: Type -> Type) b a.
Functor m =>
(b -> m (Maybe (a, b))) -> b -> ListT m a
unfoldrM b -> m (Maybe (a, b))
f = m (ListCons a (ListT m a)) -> ListT m a
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT (m (ListCons a (ListT m a)) -> ListT m a)
-> (b -> m (ListCons a (ListT m a))) -> b -> ListT m a
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (Maybe (a, b) -> ListCons a (ListT m a))
-> m (Maybe (a, b)) -> m (ListCons a (ListT m a))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap Maybe (a, b) -> ListCons a (ListT m a)
h (m (Maybe (a, b)) -> m (ListCons a (ListT m a)))
-> (b -> m (Maybe (a, b))) -> b -> m (ListCons a (ListT m a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> m (Maybe (a, b))
f
  where
    h :: Maybe (a, b) -> ListCons a (ListT m a)
h Maybe (a, b)
Nothing = ListCons a (ListT m a)
forall a b. ListCons a b
Nil
    h (Just (a
x, b
xs)) = a
x a -> ListT m a -> ListCons a (ListT m a)
forall a b. a -> b -> ListCons a b
:- m (ListCons a (ListT m a)) -> ListT m a
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT ((Maybe (a, b) -> ListCons a (ListT m a))
-> m (Maybe (a, b)) -> m (ListCons a (ListT m a))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap Maybe (a, b) -> ListCons a (ListT m a)
h (b -> m (Maybe (a, b))
f b
xs))
{-# INLINE unfoldrM #-}

instance (forall x. Show x => Show (m x), Show a) => Show (ListT m a) where
  showsPrec :: Int -> ListT m a -> ShowS
showsPrec Int
n (ListT m (ListCons a (ListT m a))
xs) = Bool -> ShowS -> ShowS
showParen (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (String -> ShowS
showString String
"ListT " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> m (ListCons a (ListT m a)) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 m (ListCons a (ListT m a))
xs)
  
instance (forall x. Read x => Read (m x), Read a) => Read (ListT m a) where
  readPrec :: ReadPrec (ListT m a)
readPrec = ReadPrec (ListT m a) -> ReadPrec (ListT m a)
forall a. ReadPrec a -> ReadPrec a
parens (ReadPrec (ListT m a) -> ReadPrec (ListT m a))
-> ReadPrec (ListT m a) -> ReadPrec (ListT m a)
forall a b. (a -> b) -> a -> b
$
      Int -> ReadPrec (ListT m a) -> ReadPrec (ListT m a)
forall a. Int -> ReadPrec a -> ReadPrec a
prec Int
10 (ReadPrec (ListT m a) -> ReadPrec (ListT m a))
-> ReadPrec (ListT m a) -> ReadPrec (ListT m a)
forall a b. (a -> b) -> a -> b
$ do
        Ident String
"ListT" <- ReadPrec Lexeme
lexP
        m (ListCons a (ListT m a))
m <- ReadPrec (m (ListCons a (ListT m a)))
-> ReadPrec (m (ListCons a (ListT m a)))
forall a. ReadPrec a -> ReadPrec a
step ReadPrec (m (ListCons a (ListT m a)))
forall a. Read a => ReadPrec a
readPrec
        return (m (ListCons a (ListT m a)) -> ListT m a
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT m (ListCons a (ListT m a))
m)
  
deriving instance (forall x. Eq x => Eq (m x), Eq a) => Eq (ListT m a)
deriving instance (forall x. Ord x => Ord (m x), Eq (ListT m a), Ord a) => Ord (ListT m a)

instance (Arbitrary1 m, Arbitrary a) => Arbitrary (ListT m a) where
  arbitrary :: Gen (ListT m a)
arbitrary = Gen (ListT m a)
forall (f :: Type -> Type) a.
(Arbitrary1 f, Arbitrary a) =>
Gen (f a)
arbitrary1
  shrink :: ListT m a -> [ListT m a]
shrink = ListT m a -> [ListT m a]
forall (f :: Type -> Type) a.
(Arbitrary1 f, Arbitrary a) =>
f a -> [f a]
shrink1

instance Arbitrary1 m => Arbitrary1 (ListT m) where
  liftArbitrary :: forall a. Gen a -> Gen (ListT m a)
liftArbitrary Gen a
arb = (Int -> Gen (ListT m a)) -> Gen (ListT m a)
forall a. (Int -> Gen a) -> Gen a
sized Int -> Gen (ListT m a)
go
    where
      go :: Int -> Gen (ListT m a)
go Int
n
        | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0    = m (ListCons a (ListT m a)) -> ListT m a
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT (m (ListCons a (ListT m a)) -> ListT m a)
-> Gen (m (ListCons a (ListT m a))) -> Gen (ListT m a)
forall (f :: Type -> Type) a b.
Coercible (f a) (f b) =>
(a -> b) -> f a -> f b
<#$> Gen (ListCons a (ListT m a)) -> Gen (m (ListCons a (ListT m a)))
forall (f :: Type -> Type) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary (ListCons a (ListT m a) -> Gen (ListCons a (ListT m a))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure ListCons a (ListT m a)
forall a b. ListCons a b
Nil)
        | Bool
otherwise = m (ListCons a (ListT m a)) -> ListT m a
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT (m (ListCons a (ListT m a)) -> ListT m a)
-> Gen (m (ListCons a (ListT m a))) -> Gen (ListT m a)
forall (f :: Type -> Type) a b.
Coercible (f a) (f b) =>
(a -> b) -> f a -> f b
<#$> Gen (ListCons a (ListT m a)) -> Gen (m (ListCons a (ListT m a)))
forall (f :: Type -> Type) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary ((a -> ListT m a -> ListCons a (ListT m a))
-> Gen a -> Gen (ListT m a) -> Gen (ListCons a (ListT m a))
forall (f :: Type -> Type) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> ListT m a -> ListCons a (ListT m a)
forall a b. a -> b -> ListCons a b
(:-) Gen a
arb (Int -> Gen (ListT m a)
go (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1)))
  liftShrink :: forall a. (a -> [a]) -> ListT m a -> [ListT m a]
liftShrink a -> [a]
shr = (m (ListCons a (ListT m a)) -> ListT m a)
-> [m (ListCons a (ListT m a))] -> [ListT m a]
forall a b. (a -> b) -> [a] -> [b]
map m (ListCons a (ListT m a)) -> ListT m a
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT ([m (ListCons a (ListT m a))] -> [ListT m a])
-> (ListT m a -> [m (ListCons a (ListT m a))])
-> ListT m a
-> [ListT m a]
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. ((ListCons a (ListT m a) -> [ListCons a (ListT m a)])
-> m (ListCons a (ListT m a)) -> [m (ListCons a (ListT m a))]
forall (f :: Type -> Type) a.
Arbitrary1 f =>
(a -> [a]) -> f a -> [f a]
liftShrink ListCons a (ListT m a) -> [ListCons a (ListT m a)]
f (m (ListCons a (ListT m a)) -> [m (ListCons a (ListT m a))])
-> (ListT m a -> m (ListCons a (ListT m a)))
-> ListT m a
-> [m (ListCons a (ListT m a))]
forall a b c. Coercible a b => (b -> c) -> (a -> b) -> a -> c
.# ListT m a -> m (ListCons a (ListT m a))
forall (m :: Type -> Type) a.
ListT m a -> m (ListCons a (ListT m a))
runListT)
    where
      f :: ListCons a (ListT m a) -> [ListCons a (ListT m a)]
f ListCons a (ListT m a)
Nil       = []
      f (a
x :- ListT m a
xs) = ListCons a (ListT m a)
forall a b. ListCons a b
Nil ListCons a (ListT m a)
-> [ListCons a (ListT m a)] -> [ListCons a (ListT m a)]
forall a. a -> [a] -> [a]
: ((a, ListT m a) -> ListCons a (ListT m a))
-> [(a, ListT m a)] -> [ListCons a (ListT m a)]
forall a b. (a -> b) -> [a] -> [b]
map ((a -> ListT m a -> ListCons a (ListT m a))
-> (a, ListT m a) -> ListCons a (ListT m a)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> ListT m a -> ListCons a (ListT m a)
forall a b. a -> b -> ListCons a b
(:-)) ((a -> [a])
-> (ListT m a -> [ListT m a]) -> (a, ListT m a) -> [(a, ListT m a)]
forall (f :: Type -> Type -> Type) a b.
Arbitrary2 f =>
(a -> [a]) -> (b -> [b]) -> f a b -> [f a b]
liftShrink2 a -> [a]
shr ((a -> [a]) -> ListT m a -> [ListT m a]
forall (f :: Type -> Type) a.
Arbitrary1 f =>
(a -> [a]) -> f a -> [f a]
liftShrink a -> [a]
shr) (a
x,ListT m a
xs))

instance (m ~ Identity) => IsList (ListT m a) where
  type Item (ListT m a) = a
  fromList :: [Item (ListT m a)] -> ListT m a
fromList = (a -> ListT Identity a -> ListT Identity a)
-> ListT Identity a -> [a] -> ListT Identity a
forall (t :: Type -> Type) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\a
x ListT Identity a
xs -> Identity (ListCons a (ListT Identity a)) -> ListT Identity a
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT (ListCons a (ListT Identity a)
-> Identity (ListCons a (ListT Identity a))
forall a. a -> Identity a
Identity (a
x a -> ListT Identity a -> ListCons a (ListT Identity a)
forall a b. a -> b -> ListCons a b
:- ListT Identity a
xs))) (Identity (ListCons a (ListT Identity a)) -> ListT Identity a
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT (ListCons a (ListT Identity a)
-> Identity (ListCons a (ListT Identity a))
forall a. a -> Identity a
Identity ListCons a (ListT Identity a)
forall a b. ListCons a b
Nil))
  toList :: ListT m a -> [Item (ListT m a)]
toList = (ListT Identity a -> Maybe (a, ListT Identity a))
-> ListT Identity a -> [a]
forall b a. (b -> Maybe (a, b)) -> b -> [a]
unfoldr ListT Identity a -> Maybe (a, ListT Identity a)
forall {a}. ListT Identity a -> Maybe (a, ListT Identity a)
f
    where
      f :: ListT Identity a -> Maybe (a, ListT Identity a)
f (ListT (Identity ListCons a (ListT Identity a)
Nil)) = Maybe (a, ListT Identity a)
forall a. Maybe a
Nothing
      f (ListT (Identity (a
x :- ListT Identity a
xs))) = (a, ListT Identity a) -> Maybe (a, ListT Identity a)
forall a. a -> Maybe a
Just (a
x, ListT Identity a
xs)

instance Functor m => Functor (ListT m) where
  fmap :: forall a b. (a -> b) -> ListT m a -> ListT m b
fmap a -> b
f = m (ListCons b (ListT m b)) -> ListT m b
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT (m (ListCons b (ListT m b)) -> ListT m b)
-> (ListT m a -> m (ListCons b (ListT m b)))
-> ListT m a
-> ListT m b
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. ((ListCons a (ListT m a) -> ListCons b (ListT m b))
-> m (ListCons a (ListT m a)) -> m (ListCons b (ListT m b))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> b)
-> (ListT m a -> ListT m b)
-> ListCons a (ListT m a)
-> ListCons b (ListT m b)
forall (p :: Type -> Type -> Type) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap a -> b
f ((a -> b) -> ListT m a -> ListT m b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f)) (m (ListCons a (ListT m a)) -> m (ListCons b (ListT m b)))
-> (ListT m a -> m (ListCons a (ListT m a)))
-> ListT m a
-> m (ListCons b (ListT m b))
forall a b c. Coercible a b => (b -> c) -> (a -> b) -> a -> c
.# ListT m a -> m (ListCons a (ListT m a))
forall (m :: Type -> Type) a.
ListT m a -> m (ListCons a (ListT m a))
runListT)
  {-# INLINE fmap #-}

foldListT :: ((ListCons a (ListT m a) -> c) -> m (ListCons a (ListT m a)) -> b)
          -> (a -> b -> c)
          -> c
          -> ListT m a -> b
foldListT :: forall a (m :: Type -> Type) c b.
((ListCons a (ListT m a) -> c) -> m (ListCons a (ListT m a)) -> b)
-> (a -> b -> c) -> c -> ListT m a -> b
foldListT (ListCons a (ListT m a) -> c) -> m (ListCons a (ListT m a)) -> b
r a -> b -> c
c c
n = (ListCons a (ListT m a) -> c) -> m (ListCons a (ListT m a)) -> b
r ListCons a (ListT m a) -> c
h (m (ListCons a (ListT m a)) -> b)
-> (ListT m a -> m (ListCons a (ListT m a))) -> ListT m a -> b
forall a b c. Coercible a b => (b -> c) -> (a -> b) -> a -> c
.# ListT m a -> m (ListCons a (ListT m a))
forall (m :: Type -> Type) a.
ListT m a -> m (ListCons a (ListT m a))
runListT
  where
    h :: ListCons a (ListT m a) -> c
h ListCons a (ListT m a)
Nil = c
n
    h (a
x :- ListT m (ListCons a (ListT m a))
xs) = a -> b -> c
c a
x ((ListCons a (ListT m a) -> c) -> m (ListCons a (ListT m a)) -> b
r ListCons a (ListT m a) -> c
h m (ListCons a (ListT m a))
xs)
{-# INLINE foldListT #-}

mapListT :: forall a m b. Monad m => (a -> ListT m b -> ListT m b) -> ListT m b -> ListT m a -> ListT m b
mapListT :: forall a (m :: Type -> Type) b.
Monad m =>
(a -> ListT m b -> ListT m b)
-> ListT m b -> ListT m a -> ListT m b
mapListT =
  ((ListCons a (ListT m a) -> ListT m b)
 -> m (ListCons a (ListT m a)) -> ListT m b)
-> (a -> ListT m b -> ListT m b)
-> ListT m b
-> ListT m a
-> ListT m b
forall a (m :: Type -> Type) c b.
((ListCons a (ListT m a) -> c) -> m (ListCons a (ListT m a)) -> b)
-> (a -> b -> c) -> c -> ListT m a -> b
foldListT 
  ((((ListCons a (ListT m a) -> m (ListCons b (ListT m b)))
 -> m (ListCons a (ListT m a)) -> m (ListCons b (ListT m b)))
-> (ListCons a (ListT m a) -> ListT m b)
-> m (ListCons a (ListT m a))
-> ListT m b
coerce :: 
 ((ListCons a (ListT m a) -> m (ListCons b (ListT m b))) -> m (ListCons a (ListT m a)) -> m (ListCons b (ListT m b))) ->
 ((ListCons a (ListT m a) -> ListT m b) -> m (ListCons a (ListT m a)) -> ListT m b))
  (ListCons a (ListT m a) -> m (ListCons b (ListT m b)))
-> m (ListCons a (ListT m a)) -> m (ListCons b (ListT m b))
forall (m :: Type -> Type) a b. Monad m => (a -> m b) -> m a -> m b
(=<<))
{-# INLINE mapListT #-}

cons :: Applicative m => a -> ListT m a -> ListT m a
cons :: forall (m :: Type -> Type) a.
Applicative m =>
a -> ListT m a -> ListT m a
cons a
x ListT m a
xs = m (ListCons a (ListT m a)) -> ListT m a
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT (ListCons a (ListT m a) -> m (ListCons a (ListT m a))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (a
x a -> ListT m a -> ListCons a (ListT m a)
forall a b. a -> b -> ListCons a b
:- ListT m a
xs))
{-# INLINE cons #-}

nil :: Applicative m => ListT m a
nil :: forall (m :: Type -> Type) a. Applicative m => ListT m a
nil = m (ListCons a (ListT m a)) -> ListT m a
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT (ListCons a (ListT m a) -> m (ListCons a (ListT m a))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure ListCons a (ListT m a)
forall a b. ListCons a b
Nil)
{-# INLINE nil #-}

instance Monad m => Applicative (ListT m) where
  pure :: forall a. a -> ListT m a
pure a
x = a -> ListT m a -> ListT m a
forall (m :: Type -> Type) a.
Applicative m =>
a -> ListT m a -> ListT m a
cons a
x ListT m a
forall (m :: Type -> Type) a. Applicative m => ListT m a
nil
  {-# INLINE pure #-}
  liftA2 :: forall a b c. (a -> b -> c) -> ListT m a -> ListT m b -> ListT m c
liftA2 a -> b -> c
f ListT m a
xs ListT m b
ys = (a -> ListT m c -> ListT m c)
-> ListT m c -> ListT m a -> ListT m c
forall a (m :: Type -> Type) b.
Monad m =>
(a -> ListT m b -> ListT m b)
-> ListT m b -> ListT m a -> ListT m b
mapListT (\a
x ListT m c
zs -> (b -> ListT m c -> ListT m c)
-> ListT m c -> ListT m b -> ListT m c
forall a (m :: Type -> Type) b.
Monad m =>
(a -> ListT m b -> ListT m b)
-> ListT m b -> ListT m a -> ListT m b
mapListT (c -> ListT m c -> ListT m c
forall (m :: Type -> Type) a.
Applicative m =>
a -> ListT m a -> ListT m a
cons (c -> ListT m c -> ListT m c)
-> (b -> c) -> b -> ListT m c -> ListT m c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b -> c
f a
x) ListT m c
zs ListT m b
ys) ListT m c
forall (f :: Type -> Type) a. Alternative f => f a
empty ListT m a
xs
  {-# INLINE liftA2 #-}
  *> :: forall a b. ListT m a -> ListT m b -> ListT m b
(*>) = (a -> b -> b) -> ListT m a -> ListT m b -> ListT m b
forall (f :: Type -> Type) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 ((b -> b) -> a -> b -> b
forall a b. a -> b -> a
const b -> b
forall a. a -> a
id)
  {-# INLINE (*>) #-}
  <* :: forall a b. ListT m a -> ListT m b -> ListT m a
(<*) = (a -> b -> a) -> ListT m a -> ListT m b -> ListT m a
forall (f :: Type -> Type) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> b -> a
forall a b. a -> b -> a
const
  {-# INLINE (<*) #-}
  
instance Monad m => Monad (ListT m) where
  ListT m a
xs >>= :: forall a b. ListT m a -> (a -> ListT m b) -> ListT m b
>>= a -> ListT m b
f = (a -> ListT m b -> ListT m b)
-> ListT m b -> ListT m a -> ListT m b
forall a (m :: Type -> Type) b.
Monad m =>
(a -> ListT m b -> ListT m b)
-> ListT m b -> ListT m a -> ListT m b
mapListT (ListT m b -> ListT m b -> ListT m b
forall (f :: Type -> Type) a. Alternative f => f a -> f a -> f a
(<|>) (ListT m b -> ListT m b -> ListT m b)
-> (a -> ListT m b) -> a -> ListT m b -> ListT m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ListT m b
f) ListT m b
forall (f :: Type -> Type) a. Alternative f => f a
empty ListT m a
xs
  {-# INLINE (>>=) #-}
  >> :: forall a b. ListT m a -> ListT m b -> ListT m b
(>>) = ListT m a -> ListT m b -> ListT m b
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f b
(*>)
  
instance Foldable m => Foldable (ListT m) where
  foldr :: forall a b. (a -> b -> b) -> b -> ListT m a -> b
foldr a -> b -> b
f = b -> ListT m a -> b
go
    where
      go :: b -> ListT m a -> b
go = ((m (ListCons a (ListT m a)) -> b)
-> (ListT m a -> m (ListCons a (ListT m a))) -> ListT m a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ListT m a -> m (ListCons a (ListT m a))
forall (m :: Type -> Type) a.
ListT m a -> m (ListCons a (ListT m a))
runListT) ((m (ListCons a (ListT m a)) -> b) -> ListT m a -> b)
-> (b -> m (ListCons a (ListT m a)) -> b) -> b -> ListT m a -> b
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (ListCons a (ListT m a) -> b -> b)
-> b -> m (ListCons a (ListT m a)) -> b
forall (t :: Type -> Type) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((b -> ListCons a (ListT m a) -> b)
-> ListCons a (ListT m a) -> b -> b
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> b -> b)
-> (ListT m a -> b -> b) -> b -> ListCons a (ListT m a) -> b
forall (p :: Type -> Type -> Type) a c b.
Bifoldable p =>
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr a -> b -> b
f ((b -> ListT m a -> b) -> ListT m a -> b -> b
forall a b c. (a -> b -> c) -> b -> a -> c
flip b -> ListT m a -> b
go)))
  {-# INLINE foldr #-}

  foldMap :: forall m a. Monoid m => (a -> m) -> ListT m a -> m
foldMap a -> m
f = ((ListCons a (ListT m a) -> m) -> m (ListCons a (ListT m a)) -> m)
-> (a -> m -> m) -> m -> ListT m a -> m
forall a (m :: Type -> Type) c b.
((ListCons a (ListT m a) -> c) -> m (ListCons a (ListT m a)) -> b)
-> (a -> b -> c) -> c -> ListT m a -> b
foldListT (ListCons a (ListT m a) -> m) -> m (ListCons a (ListT m a)) -> m
forall (t :: Type -> Type) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (m -> m -> m
forall a. Semigroup a => a -> a -> a
(<>) (m -> m -> m) -> (a -> m) -> a -> m -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m
f) m
forall a. Monoid a => a
mempty
  {-# INLINE foldMap #-}
  foldl :: forall b a. (b -> a -> b) -> b -> ListT m a -> b
foldl b -> a -> b
f = b -> ListT m a -> b
go
    where
      go :: b -> ListT m a -> b
go = ((m (ListCons a (ListT m a)) -> b)
-> (ListT m a -> m (ListCons a (ListT m a))) -> ListT m a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ListT m a -> m (ListCons a (ListT m a))
forall (m :: Type -> Type) a.
ListT m a -> m (ListCons a (ListT m a))
runListT) ((m (ListCons a (ListT m a)) -> b) -> ListT m a -> b)
-> (b -> m (ListCons a (ListT m a)) -> b) -> b -> ListT m a -> b
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (b -> ListCons a (ListT m a) -> b)
-> b -> m (ListCons a (ListT m a)) -> b
forall (t :: Type -> Type) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl ((b -> a -> b)
-> (b -> ListT m a -> b) -> b -> ListCons a (ListT m a) -> b
forall (p :: Type -> Type -> Type) c a b.
Bifoldable p =>
(c -> a -> c) -> (c -> b -> c) -> c -> p a b -> c
bifoldl b -> a -> b
f b -> ListT m a -> b
go)
  {-# INLINE foldl #-}
  
  foldl' :: forall b a. (b -> a -> b) -> b -> ListT m a -> b
foldl' b -> a -> b
f = b -> ListT m a -> b
go
    where
      go :: b -> ListT m a -> b
go = ((m (ListCons a (ListT m a)) -> b)
-> (ListT m a -> m (ListCons a (ListT m a))) -> ListT m a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ListT m a -> m (ListCons a (ListT m a))
forall (m :: Type -> Type) a.
ListT m a -> m (ListCons a (ListT m a))
runListT) ((m (ListCons a (ListT m a)) -> b) -> ListT m a -> b)
-> (b -> m (ListCons a (ListT m a)) -> b) -> b -> ListT m a -> b
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (b -> ListCons a (ListT m a) -> b)
-> b -> m (ListCons a (ListT m a)) -> b
forall (t :: Type -> Type) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' ((b -> a -> b)
-> (b -> ListT m a -> b) -> b -> ListCons a (ListT m a) -> b
forall (t :: Type -> Type -> Type) a b c.
Bifoldable t =>
(a -> b -> a) -> (a -> c -> a) -> a -> t b c -> a
bifoldl' b -> a -> b
f b -> ListT m a -> b
go)
  {-# INLINE foldl' #-}
  
  foldr' :: forall a b. (a -> b -> b) -> b -> ListT m a -> b
foldr' a -> b -> b
f = b -> ListT m a -> b
go
    where
      go :: b -> ListT m a -> b
go = ((m (ListCons a (ListT m a)) -> b)
-> (ListT m a -> m (ListCons a (ListT m a))) -> ListT m a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ListT m a -> m (ListCons a (ListT m a))
forall (m :: Type -> Type) a.
ListT m a -> m (ListCons a (ListT m a))
runListT) ((m (ListCons a (ListT m a)) -> b) -> ListT m a -> b)
-> (b -> m (ListCons a (ListT m a)) -> b) -> b -> ListT m a -> b
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (ListCons a (ListT m a) -> b -> b)
-> b -> m (ListCons a (ListT m a)) -> b
forall (t :: Type -> Type) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr' ((b -> ListCons a (ListT m a) -> b)
-> ListCons a (ListT m a) -> b -> b
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> b -> b)
-> (ListT m a -> b -> b) -> b -> ListCons a (ListT m a) -> b
forall (t :: Type -> Type -> Type) a c b.
Bifoldable t =>
(a -> c -> c) -> (b -> c -> c) -> c -> t a b -> c
bifoldr' a -> b -> b
f ((b -> ListT m a -> b) -> ListT m a -> b -> b
forall a b c. (a -> b -> c) -> b -> a -> c
flip b -> ListT m a -> b
go)))
  {-# INLINE foldr' #-}

instance Traversable m => Traversable (ListT m) where
  traverse :: forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> ListT m a -> f (ListT m b)
traverse a -> f b
f = (m (ListCons b (ListT m b)) -> ListT m b)
-> f (m (ListCons b (ListT m b))) -> f (ListT m b)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap m (ListCons b (ListT m b)) -> ListT m b
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT (f (m (ListCons b (ListT m b))) -> f (ListT m b))
-> (ListT m a -> f (m (ListCons b (ListT m b))))
-> ListT m a
-> f (ListT m b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((ListCons a (ListT m a) -> f (ListCons b (ListT m b)))
-> m (ListCons a (ListT m a)) -> f (m (ListCons b (ListT m b)))
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ListCons a (ListT m a) -> f (ListCons b (ListT m b))
h (m (ListCons a (ListT m a)) -> f (m (ListCons b (ListT m b))))
-> (ListT m a -> m (ListCons a (ListT m a)))
-> ListT m a
-> f (m (ListCons b (ListT m b)))
forall a b c. Coercible a b => (b -> c) -> (a -> b) -> a -> c
.# ListT m a -> m (ListCons a (ListT m a))
forall (m :: Type -> Type) a.
ListT m a -> m (ListCons a (ListT m a))
runListT)
    where
      h :: ListCons a (ListT m a) -> f (ListCons b (ListT m b))
h ListCons a (ListT m a)
Nil = ListCons b (ListT m b) -> f (ListCons b (ListT m b))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure ListCons b (ListT m b)
forall a b. ListCons a b
Nil
      h (a
x :- ListT m (ListCons a (ListT m a))
xs) = (b -> m (ListCons b (ListT m b)) -> ListCons b (ListT m b))
-> f b
-> f (m (ListCons b (ListT m b)))
-> f (ListCons b (ListT m b))
forall (f :: Type -> Type) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (((ListT m b -> ListCons b (ListT m b))
-> (m (ListCons b (ListT m b)) -> ListT m b)
-> m (ListCons b (ListT m b))
-> ListCons b (ListT m b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (ListCons b (ListT m b)) -> ListT m b
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT) ((ListT m b -> ListCons b (ListT m b))
 -> m (ListCons b (ListT m b)) -> ListCons b (ListT m b))
-> (b -> ListT m b -> ListCons b (ListT m b))
-> b
-> m (ListCons b (ListT m b))
-> ListCons b (ListT m b)
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. b -> ListT m b -> ListCons b (ListT m b)
forall a b. a -> b -> ListCons a b
(:-)) (a -> f b
f a
x) ((ListCons a (ListT m a) -> f (ListCons b (ListT m b)))
-> m (ListCons a (ListT m a)) -> f (m (ListCons b (ListT m b)))
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ListCons a (ListT m a) -> f (ListCons b (ListT m b))
h m (ListCons a (ListT m a))
xs)
  {-# INLINE traverse #-}

-- | Flatten all of the effects in the list and collect the results.
toListT :: Monad m => ListT m a -> m [a]
toListT :: forall (m :: Type -> Type) a. Monad m => ListT m a -> m [a]
toListT ListT m a
xs = ((ListCons a (ListT m a) -> [a] -> m [a])
 -> m (ListCons a (ListT m a)) -> [a] -> m [a])
-> (a -> ([a] -> m [a]) -> [a] -> m [a])
-> ([a] -> m [a])
-> ListT m a
-> [a]
-> m [a]
forall a (m :: Type -> Type) c b.
((ListCons a (ListT m a) -> c) -> m (ListCons a (ListT m a)) -> b)
-> (a -> b -> c) -> c -> ListT m a -> b
foldListT (\ListCons a (ListT m a) -> [a] -> m [a]
k m (ListCons a (ListT m a))
mx [a]
xs -> m (ListCons a (ListT m a))
mx m (ListCons a (ListT m a))
-> (ListCons a (ListT m a) -> m [a]) -> m [a]
forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ListCons a (ListT m a) -> [a] -> m [a])
-> [a] -> ListCons a (ListT m a) -> m [a]
forall a b c. (a -> b -> c) -> b -> a -> c
flip ListCons a (ListT m a) -> [a] -> m [a]
k [a]
xs) (\a
x [a] -> m [a]
k [a]
xs -> [a] -> m [a]
k (a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
xs)) ([a] -> m [a]
forall (m :: Type -> Type) a. Monad m => a -> m a
return ([a] -> m [a]) -> ([a] -> [a]) -> [a] -> m [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [a]
forall a. [a] -> [a]
reverse) ListT m a
xs []
{-# INLINE toListT #-}

fromListT :: Applicative m => [a] -> ListT m a
fromListT :: forall (m :: Type -> Type) a. Applicative m => [a] -> ListT m a
fromListT = (a -> ListT m a -> ListT m a) -> ListT m a -> [a] -> ListT m a
forall (t :: Type -> Type) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr a -> ListT m a -> ListT m a
forall (m :: Type -> Type) a.
Applicative m =>
a -> ListT m a -> ListT m a
cons ListT m a
forall (m :: Type -> Type) a. Applicative m => ListT m a
nil
{-# INLINE fromListT #-}

instance Monad m => Alternative (ListT m) where
  <|> :: forall a. ListT m a -> ListT m a -> ListT m a
(<|>) = (ListT m a -> ListT m a -> ListT m a)
-> ListT m a -> ListT m a -> ListT m a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> ListT m a -> ListT m a)
-> ListT m a -> ListT m a -> ListT m a
forall a (m :: Type -> Type) b.
Monad m =>
(a -> ListT m b -> ListT m b)
-> ListT m b -> ListT m a -> ListT m b
mapListT a -> ListT m a -> ListT m a
forall (m :: Type -> Type) a.
Applicative m =>
a -> ListT m a -> ListT m a
cons)
  {-# INLINE (<|>) #-}
  empty :: forall a. ListT m a
empty = m (ListCons a (ListT m a)) -> ListT m a
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT (ListCons a (ListT m a) -> m (ListCons a (ListT m a))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure ListCons a (ListT m a)
forall a b. ListCons a b
Nil)
  {-# INLINE empty #-}
  
instance Monad m => MonadPlus (ListT m)

instance MonadTrans ListT where
  lift :: forall (m :: Type -> Type) a. Monad m => m a -> ListT m a
lift = m (ListCons a (ListT m a)) -> ListT m a
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT (m (ListCons a (ListT m a)) -> ListT m a)
-> (m a -> m (ListCons a (ListT m a))) -> m a -> ListT m a
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (a -> ListCons a (ListT m a)) -> m a -> m (ListCons a (ListT m a))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> ListT m a -> ListCons a (ListT m a)
forall a b. a -> b -> ListCons a b
:- m (ListCons a (ListT m a)) -> ListT m a
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT (ListCons a (ListT m a) -> m (ListCons a (ListT m a))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure ListCons a (ListT m a)
forall a b. ListCons a b
Nil))
  {-# INLINE lift #-}
  
-- | Apply a function to every effect layered in the list transformer.
listMmap :: Functor m
         => (m (ListCons a (ListT n b)) -> n (ListCons b (ListT n b)))
         -> ListT m a -> ListT n b
listMmap :: forall (m :: Type -> Type) a (n :: Type -> Type) b.
Functor m =>
(m (ListCons a (ListT n b)) -> n (ListCons b (ListT n b)))
-> ListT m a -> ListT n b
listMmap m (ListCons a (ListT n b)) -> n (ListCons b (ListT n b))
f = ListT m a -> ListT n b
go
  where
    go :: ListT m a -> ListT n b
go = n (ListCons b (ListT n b)) -> ListT n b
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT (n (ListCons b (ListT n b)) -> ListT n b)
-> (ListT m a -> n (ListCons b (ListT n b)))
-> ListT m a
-> ListT n b
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. m (ListCons a (ListT n b)) -> n (ListCons b (ListT n b))
f (m (ListCons a (ListT n b)) -> n (ListCons b (ListT n b)))
-> (ListT m a -> m (ListCons a (ListT n b)))
-> ListT m a
-> n (ListCons b (ListT n b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((ListCons a (ListT m a) -> ListCons a (ListT n b))
-> m (ListCons a (ListT m a)) -> m (ListCons a (ListT n b))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ListT m a -> ListT n b)
-> ListCons a (ListT m a) -> ListCons a (ListT n b)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap ListT m a -> ListT n b
go) (m (ListCons a (ListT m a)) -> m (ListCons a (ListT n b)))
-> (ListT m a -> m (ListCons a (ListT m a)))
-> ListT m a
-> m (ListCons a (ListT n b))
forall a b c. Coercible a b => (b -> c) -> (a -> b) -> a -> c
.# ListT m a -> m (ListCons a (ListT m a))
forall (m :: Type -> Type) a.
ListT m a -> m (ListCons a (ListT m a))
runListT)
{-# INLINE listMmap #-}

instance MonadState s m => MonadState s (ListT m) where
  get :: ListT m s
get = m s -> ListT m s
forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m s
forall s (m :: Type -> Type). MonadState s m => m s
get
  put :: s -> ListT m ()
put = m () -> ListT m ()
forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ListT m ()) -> (s -> m ()) -> s -> ListT m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> m ()
forall s (m :: Type -> Type). MonadState s m => s -> m ()
put
  state :: forall a. (s -> (a, s)) -> ListT m a
state = m a -> ListT m a
forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ListT m a)
-> ((s -> (a, s)) -> m a) -> (s -> (a, s)) -> ListT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (s -> (a, s)) -> m a
forall s (m :: Type -> Type) a.
MonadState s m =>
(s -> (a, s)) -> m a
state
  {-# INLINE get #-}
  {-# INLINE put #-}
  {-# INLINE state #-}
  
instance MonadError e m => MonadError e (ListT m) where
  throwError :: forall a. e -> ListT m a
throwError = m a -> ListT m a
forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ListT m a) -> (e -> m a) -> e -> ListT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m a
forall e (m :: Type -> Type) a. MonadError e m => e -> m a
throwError
  {-# INLINE throwError #-}
  catchError :: forall a. ListT m a -> (e -> ListT m a) -> ListT m a
catchError ListT m a
xs e -> ListT m a
h = (m (ListCons a (ListT m a)) -> m (ListCons a (ListT m a)))
-> ListT m a -> ListT m a
forall (m :: Type -> Type) a (n :: Type -> Type) b.
Functor m =>
(m (ListCons a (ListT n b)) -> n (ListCons b (ListT n b)))
-> ListT m a -> ListT n b
listMmap (m (ListCons a (ListT m a))
-> (e -> m (ListCons a (ListT m a))) -> m (ListCons a (ListT m a))
forall e (m :: Type -> Type) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` (ListT m a -> m (ListCons a (ListT m a))
forall (m :: Type -> Type) a.
ListT m a -> m (ListCons a (ListT m a))
runListT (ListT m a -> m (ListCons a (ListT m a)))
-> (e -> ListT m a) -> e -> m (ListCons a (ListT m a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> ListT m a
h)) ListT m a
xs
  {-# INLINE catchError #-}
  
instance MonadReader r m => MonadReader r (ListT m) where
  ask :: ListT m r
ask = m r -> ListT m r
forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m r
forall r (m :: Type -> Type). MonadReader r m => m r
ask
  {-# INLINE ask #-}
  reader :: forall a. (r -> a) -> ListT m a
reader = m a -> ListT m a
forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ListT m a) -> ((r -> a) -> m a) -> (r -> a) -> ListT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r -> a) -> m a
forall r (m :: Type -> Type) a. MonadReader r m => (r -> a) -> m a
reader
  {-# INLINE reader #-}
  local :: forall a. (r -> r) -> ListT m a -> ListT m a
local = (m (ListCons a (ListT m a)) -> m (ListCons a (ListT m a)))
-> ListT m a -> ListT m a
forall (m :: Type -> Type) a (n :: Type -> Type) b.
Functor m =>
(m (ListCons a (ListT n b)) -> n (ListCons b (ListT n b)))
-> ListT m a -> ListT n b
listMmap ((m (ListCons a (ListT m a)) -> m (ListCons a (ListT m a)))
 -> ListT m a -> ListT m a)
-> ((r -> r)
    -> m (ListCons a (ListT m a)) -> m (ListCons a (ListT m a)))
-> (r -> r)
-> ListT m a
-> ListT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r -> r)
-> m (ListCons a (ListT m a)) -> m (ListCons a (ListT m a))
forall r (m :: Type -> Type) a.
MonadReader r m =>
(r -> r) -> m a -> m a
local
  {-# INLINE local #-}
  
instance MonadWriter w m => MonadWriter w (ListT m) where
  writer :: forall a. (a, w) -> ListT m a
writer = m a -> ListT m a
forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ListT m a) -> ((a, w) -> m a) -> (a, w) -> ListT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, w) -> m a
forall w (m :: Type -> Type) a. MonadWriter w m => (a, w) -> m a
writer
  {-# INLINE writer #-}
  tell :: w -> ListT m ()
tell = m () -> ListT m ()
forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ListT m ()) -> (w -> m ()) -> w -> ListT m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. w -> m ()
forall w (m :: Type -> Type). MonadWriter w m => w -> m ()
tell
  {-# INLINE tell #-}
  listen :: forall a. ListT m a -> ListT m (a, w)
listen = (m (ListCons a (ListT m (a, w)))
 -> m (ListCons (a, w) (ListT m (a, w))))
-> ListT m a -> ListT m (a, w)
forall (m :: Type -> Type) a (n :: Type -> Type) b.
Functor m =>
(m (ListCons a (ListT n b)) -> n (ListCons b (ListT n b)))
-> ListT m a -> ListT n b
listMmap (((ListCons a (ListT m (a, w)), w)
 -> ListCons (a, w) (ListT m (a, w)))
-> m (ListCons a (ListT m (a, w)), w)
-> m (ListCons (a, w) (ListT m (a, w)))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ListCons a (ListT m (a, w))
 -> w -> ListCons (a, w) (ListT m (a, w)))
-> (ListCons a (ListT m (a, w)), w)
-> ListCons (a, w) (ListT m (a, w))
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ((w
 -> ListCons a (ListT m (a, w)) -> ListCons (a, w) (ListT m (a, w)))
-> ListCons a (ListT m (a, w))
-> w
-> ListCons (a, w) (ListT m (a, w))
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> (a, w))
-> ListCons a (ListT m (a, w)) -> ListCons (a, w) (ListT m (a, w))
forall (p :: Type -> Type -> Type) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ((a -> (a, w))
 -> ListCons a (ListT m (a, w)) -> ListCons (a, w) (ListT m (a, w)))
-> (w -> a -> (a, w))
-> w
-> ListCons a (ListT m (a, w))
-> ListCons (a, w) (ListT m (a, w))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> w -> (a, w)) -> w -> a -> (a, w)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (,)))) (m (ListCons a (ListT m (a, w)), w)
 -> m (ListCons (a, w) (ListT m (a, w))))
-> (m (ListCons a (ListT m (a, w)))
    -> m (ListCons a (ListT m (a, w)), w))
-> m (ListCons a (ListT m (a, w)))
-> m (ListCons (a, w) (ListT m (a, w)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (ListCons a (ListT m (a, w)))
-> m (ListCons a (ListT m (a, w)), w)
forall w (m :: Type -> Type) a. MonadWriter w m => m a -> m (a, w)
listen)
  {-# INLINE listen #-}
  pass :: forall a. ListT m (a, w -> w) -> ListT m a
pass = (m (ListCons (a, w -> w) (ListT m a))
 -> m (ListCons a (ListT m a)))
-> ListT m (a, w -> w) -> ListT m a
forall (m :: Type -> Type) a (n :: Type -> Type) b.
Functor m =>
(m (ListCons a (ListT n b)) -> n (ListCons b (ListT n b)))
-> ListT m a -> ListT n b
listMmap (m (ListCons a (ListT m a), w -> w) -> m (ListCons a (ListT m a))
forall w (m :: Type -> Type) a.
MonadWriter w m =>
m (a, w -> w) -> m a
pass (m (ListCons a (ListT m a), w -> w) -> m (ListCons a (ListT m a)))
-> (m (ListCons (a, w -> w) (ListT m a))
    -> m (ListCons a (ListT m a), w -> w))
-> m (ListCons (a, w -> w) (ListT m a))
-> m (ListCons a (ListT m a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ListCons (a, w -> w) (ListT m a)
 -> (ListCons a (ListT m a), w -> w))
-> m (ListCons (a, w -> w) (ListT m a))
-> m (ListCons a (ListT m a), w -> w)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap ListCons (a, w -> w) (ListT m a)
-> (ListCons a (ListT m a), w -> w)
forall {a} {a} {b}.
ListCons (a, a -> a) b -> (ListCons a b, a -> a)
h)
    where
      h :: ListCons (a, a -> a) b -> (ListCons a b, a -> a)
h ListCons (a, a -> a) b
Nil = (ListCons a b
forall a b. ListCons a b
Nil, a -> a
forall a. a -> a
id)
      h ((a
x,a -> a
f):-b
xs) = (a
x a -> b -> ListCons a b
forall a b. a -> b -> ListCons a b
:- b
xs , a -> a
f)
  {-# INLINE pass #-}

instance MonadCont m => MonadCont (ListT m) where
  callCC :: forall a b. ((a -> ListT m b) -> ListT m a) -> ListT m a
callCC (a -> ListT m b) -> ListT m a
f = m (ListCons a (ListT m a)) -> ListT m a
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT (((ListCons a (ListT m a) -> m (ListCons b (ListT m b)))
 -> m (ListCons a (ListT m a)))
-> m (ListCons a (ListT m a))
forall (m :: Type -> Type) a b.
MonadCont m =>
((a -> m b) -> m a) -> m a
callCC (\ListCons a (ListT m a) -> m (ListCons b (ListT m b))
c -> ListT m a -> m (ListCons a (ListT m a))
forall (m :: Type -> Type) a.
ListT m a -> m (ListCons a (ListT m a))
runListT ((a -> ListT m b) -> ListT m a
f (m (ListCons b (ListT m b)) -> ListT m b
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT (m (ListCons b (ListT m b)) -> ListT m b)
-> (a -> m (ListCons b (ListT m b))) -> a -> ListT m b
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. ListCons a (ListT m a) -> m (ListCons b (ListT m b))
c (ListCons a (ListT m a) -> m (ListCons b (ListT m b)))
-> (a -> ListCons a (ListT m a)) -> a -> m (ListCons b (ListT m b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> ListT m a -> ListCons a (ListT m a)
forall a b. a -> b -> ListCons a b
:- ListT m a
forall (f :: Type -> Type) a. Alternative f => f a
empty)))))
  {-# INLINE callCC #-}

-- | Filter the list. An analogue of mapMaybe on lists.
catMaybesT :: Monad m => (a -> Maybe b) -> ListT m a -> ListT m b
catMaybesT :: forall (m :: Type -> Type) a b.
Monad m =>
(a -> Maybe b) -> ListT m a -> ListT m b
catMaybesT a -> Maybe b
f = (a -> ListT m b -> ListT m b)
-> ListT m b -> ListT m a -> ListT m b
forall a (m :: Type -> Type) b.
Monad m =>
(a -> ListT m b -> ListT m b)
-> ListT m b -> ListT m a -> ListT m b
mapListT ((ListT m b -> ListT m b)
-> (b -> ListT m b -> ListT m b)
-> Maybe b
-> ListT m b
-> ListT m b
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ListT m b -> ListT m b
forall a. a -> a
id b -> ListT m b -> ListT m b
forall (m :: Type -> Type) a.
Applicative m =>
a -> ListT m a -> ListT m a
cons (Maybe b -> ListT m b -> ListT m b)
-> (a -> Maybe b) -> a -> ListT m b -> ListT m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe b
f) ListT m b
forall (f :: Type -> Type) a. Alternative f => f a
empty
{-# INLINE catMaybesT #-}

scanl1M :: Functor m => (a -> a -> a) -> ListT m a -> ListT m a
scanl1M :: forall (m :: Type -> Type) a.
Functor m =>
(a -> a -> a) -> ListT m a -> ListT m a
scanl1M a -> a -> a
f ListT m a
xs = ((ListCons a (ListT m a) -> Maybe a -> ListCons a (ListT m a))
 -> m (ListCons a (ListT m a)) -> Maybe a -> ListT m a)
-> (a
    -> (Maybe a -> ListT m a) -> Maybe a -> ListCons a (ListT m a))
-> (Maybe a -> ListCons a (ListT m a))
-> ListT m a
-> Maybe a
-> ListT m a
forall a (m :: Type -> Type) c b.
((ListCons a (ListT m a) -> c) -> m (ListCons a (ListT m a)) -> b)
-> (a -> b -> c) -> c -> ListT m a -> b
foldListT (\ListCons a (ListT m a) -> Maybe a -> ListCons a (ListT m a)
k m (ListCons a (ListT m a))
mx Maybe a
x -> m (ListCons a (ListT m a)) -> ListT m a
forall (m :: Type -> Type) a.
m (ListCons a (ListT m a)) -> ListT m a
ListT ((ListCons a (ListT m a) -> ListCons a (ListT m a))
-> m (ListCons a (ListT m a)) -> m (ListCons a (ListT m a))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap (ListCons a (ListT m a) -> Maybe a -> ListCons a (ListT m a)
`k` Maybe a
x) m (ListCons a (ListT m a))
mx)) a -> (Maybe a -> ListT m a) -> Maybe a -> ListCons a (ListT m a)
h (ListCons a (ListT m a) -> Maybe a -> ListCons a (ListT m a)
forall a b. a -> b -> a
const ListCons a (ListT m a)
forall a b. ListCons a b
Nil) ListT m a
xs Maybe a
forall a. Maybe a
Nothing
  where
    h :: a -> (Maybe a -> ListT m a) -> Maybe a -> ListCons a (ListT m a)
h a
x Maybe a -> ListT m a
k Maybe a
Nothing  = a
x a -> ListT m a -> ListCons a (ListT m a)
forall a b. a -> b -> ListCons a b
:- Maybe a -> ListT m a
k (a -> Maybe a
forall a. a -> Maybe a
Just a
x)
    h a
x Maybe a -> ListT m a
k (Just a
y) = let z :: a
z = a -> a -> a
f a
y a
x in a
z a -> ListT m a -> ListCons a (ListT m a)
forall a b. a -> b -> ListCons a b
:- Maybe a -> ListT m a
k (a -> Maybe a
forall a. a -> Maybe a
Just a
z)
{-# INLINE scanl1M #-}