module Control.Monad.Trans.List.Church where
import Control.Applicative
import Control.Monad
import Control.Monad.Base
import Control.Monad.Trans
import qualified Control.Monad.Catch as C
import qualified Control.Monad.Fail as Fail
import Control.Effect.Carrier
import Control.Effect.Type.ListenPrim
import Control.Effect.Type.WriterPrim
import Control.Effect.Type.Regional
import Control.Effect.Type.Optional
import Control.Effect.Type.Unravel
import Control.Effect.Type.ReaderPrim
newtype ListT (m :: * -> *) a = ListT {
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT :: forall r
. (a -> m r -> m r)
-> m r
-> m r
-> m r
}
cons :: a -> ListT m a -> ListT m a
cons :: a -> ListT m a -> ListT m a
cons a
a ListT m a
m = (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall (m :: * -> *) a.
(forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
ListT ((forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a)
-> (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall a b. (a -> b) -> a -> b
$ \a -> m r -> m r
c m r
b m r
t -> a -> m r -> m r
c a
a (ListT m a -> (a -> m r -> m r) -> m r -> m r -> m r
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT ListT m a
m a -> m r -> m r
c m r
b m r
t)
instance ThreadsEff ListT (Regional s) where
threadEff :: (forall x. Regional s m x -> m x)
-> Regional s (ListT m) a -> ListT m a
threadEff = (forall x. Regional s m x -> m x)
-> Regional s (ListT m) a -> ListT m a
forall (t :: (* -> *) -> * -> *) s (m :: * -> *) a.
(ThreadsEff t (Optional (Const s)), Monad m) =>
(forall x. Regional s m x -> m x) -> Regional s (t m) a -> t m a
threadRegionalViaOptional
instance Functor s => ThreadsEff ListT (Optional s) where
threadEff :: (forall x. Optional s m x -> m x)
-> Optional s (ListT m) a -> ListT m a
threadEff forall x. Optional s m x -> m x
alg (Optionally s a
s ListT m a
main) = (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall (m :: * -> *) a.
(forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
ListT ((forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a)
-> (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall a b. (a -> b) -> a -> b
$ \a -> m r -> m r
c m r
b m r
t ->
let
n :: m (m r) -> m (m r)
n = \m (m r)
m -> Optional s m (m r) -> m (m r)
forall x. Optional s m x -> m x
alg (s (m r) -> m (m r) -> Optional s m (m r)
forall (s :: * -> *) a (m :: * -> *). s a -> m a -> Optional s m a
Optionally ((a -> m r) -> s a -> s (m r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> m r -> m r
`c` m r
b) s a
s) m (m r)
m)
in
m (m r) -> m r
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (m (m r) -> m r) -> m (m r) -> m r
forall a b. (a -> b) -> a -> b
$ m (m r) -> m (m r)
n
(m (m r) -> m (m r)) -> m (m r) -> m (m r)
forall a b. (a -> b) -> a -> b
$ ListT m a
-> (a -> m (m r) -> m (m r)) -> m (m r) -> m (m r) -> m (m r)
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT ListT m a
main
(\a
a m (m r)
r -> m r -> m (m r)
forall (m :: * -> *) a. Monad m => a -> m a
return (m r -> m (m r)) -> m r -> m (m r)
forall a b. (a -> b) -> a -> b
$ a -> m r -> m r
c a
a (m (m r) -> m r
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (m (m r) -> m (m r)
n m (m r)
r)))
(m r -> m (m r)
forall (m :: * -> *) a. Monad m => a -> m a
return m r
b)
(m r -> m (m r)
forall (m :: * -> *) a. Monad m => a -> m a
return m r
t)
{-# INLINE threadEff #-}
instance ThreadsEff ListT (Unravel p) where
threadEff :: (forall x. Unravel p m x -> m x)
-> Unravel p (ListT m) a -> ListT m a
threadEff forall x. Unravel p m x -> m x
alg (Unravel p a
p ListT m a -> a
cataM ListT m a
main) =
let
n :: m a -> m a
n = \m a
m' -> Unravel p m a -> m a
forall x. Unravel p m x -> m x
alg (p a -> (m a -> a) -> m a -> Unravel p m a
forall (p :: * -> *) a (m :: * -> *).
p a -> (m a -> a) -> m a -> Unravel p m a
Unravel p a
p (ListT m a -> a
cataM (ListT m a -> a) -> (m a -> ListT m a) -> m a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> ListT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift) m a
m')
in
m a -> ListT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ListT m a) -> m a -> ListT m a
forall a b. (a -> b) -> a -> b
$ m a -> m a
n
(m a -> m a) -> m a -> m a
forall a b. (a -> b) -> a -> b
$ ListT m a -> (a -> m a -> m a) -> m a -> m a -> m a
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT ListT m a
main
(\a
a m a
r -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> m a) -> a -> m a
forall a b. (a -> b) -> a -> b
$ ListT m a -> a
cataM (ListT m a -> a) -> ListT m a -> a
forall a b. (a -> b) -> a -> b
$ a -> ListT m a -> ListT m a
forall a (m :: * -> *). a -> ListT m a -> ListT m a
cons a
a (m a -> ListT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> m a
n m a
r)))
(a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> m a) -> a -> m a
forall a b. (a -> b) -> a -> b
$ ListT m a -> a
cataM ListT m a
forall (m :: * -> *) a. ListT m a
lose)
(a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> m a) -> a -> m a
forall a b. (a -> b) -> a -> b
$ ListT m a -> a
cataM ListT m a
forall (m :: * -> *) a. ListT m a
cutfail)
{-# INLINE threadEff #-}
instance Monoid s => ThreadsEff ListT (ListenPrim s) where
threadEff :: (forall x. ListenPrim s m x -> m x)
-> ListenPrim s (ListT m) a -> ListT m a
threadEff = (forall x.
(forall x. ListenPrim s m x -> m x) -> ListT m x -> ListT m (s, x))
-> (forall x. ListenPrim s m x -> m x)
-> ListenPrim s (ListT m) a
-> ListT m a
forall o (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
(forall x.
(forall y. ListenPrim o m y -> m y) -> t m x -> t m (o, x))
-> (forall y. ListenPrim o m y -> m y)
-> ListenPrim o (t m) a
-> t m a
threadListenPrim ((forall x.
(forall x. ListenPrim s m x -> m x) -> ListT m x -> ListT m (s, x))
-> (forall x. ListenPrim s m x -> m x)
-> ListenPrim s (ListT m) a
-> ListT m a)
-> (forall x.
(forall x. ListenPrim s m x -> m x) -> ListT m x -> ListT m (s, x))
-> (forall x. ListenPrim s m x -> m x)
-> ListenPrim s (ListT m) a
-> ListT m a
forall a b. (a -> b) -> a -> b
$ \forall x. ListenPrim s m x -> m x
alg ListT m x
main ->
let
listenStack :: LayeredListT m x -> LayeredListT m (s, x)
listenStack LayeredListT m x
m = m (Either LoseOrCutfail ((s, x), LayeredListT m (s, x)))
-> LayeredListT m (s, x)
forall (m :: * -> *) a.
m (Either LoseOrCutfail (a, LayeredListT m a)) -> LayeredListT m a
LayeredListT (m (Either LoseOrCutfail ((s, x), LayeredListT m (s, x)))
-> LayeredListT m (s, x))
-> m (Either LoseOrCutfail ((s, x), LayeredListT m (s, x)))
-> LayeredListT m (s, x)
forall a b. (a -> b) -> a -> b
$ do
(s
s, Either LoseOrCutfail (x, LayeredListT m x)
e) <- ListenPrim s m (s, Either LoseOrCutfail (x, LayeredListT m x))
-> m (s, Either LoseOrCutfail (x, LayeredListT m x))
forall x. ListenPrim s m x -> m x
alg (m (Either LoseOrCutfail (x, LayeredListT m x))
-> ListenPrim s m (s, Either LoseOrCutfail (x, LayeredListT m x))
forall (m :: * -> *) a o. m a -> ListenPrim o m (o, a)
ListenPrimListen (LayeredListT m x -> m (Either LoseOrCutfail (x, LayeredListT m x))
forall (m :: * -> *) a.
LayeredListT m a -> m (Either LoseOrCutfail (a, LayeredListT m a))
unLayeredListT LayeredListT m x
m))
case Either LoseOrCutfail (x, LayeredListT m x)
e of
Right (x
a, LayeredListT m x
r) -> Either LoseOrCutfail ((s, x), LayeredListT m (s, x))
-> m (Either LoseOrCutfail ((s, x), LayeredListT m (s, x)))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either LoseOrCutfail ((s, x), LayeredListT m (s, x))
-> m (Either LoseOrCutfail ((s, x), LayeredListT m (s, x))))
-> Either LoseOrCutfail ((s, x), LayeredListT m (s, x))
-> m (Either LoseOrCutfail ((s, x), LayeredListT m (s, x)))
forall a b. (a -> b) -> a -> b
$ ((s, x), LayeredListT m (s, x))
-> Either LoseOrCutfail ((s, x), LayeredListT m (s, x))
forall a b. b -> Either a b
Right ((s
s, x
a), LayeredListT m x -> LayeredListT m (s, x)
listenStack LayeredListT m x
r)
Left LoseOrCutfail
failure -> Either LoseOrCutfail ((s, x), LayeredListT m (s, x))
-> m (Either LoseOrCutfail ((s, x), LayeredListT m (s, x)))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either LoseOrCutfail ((s, x), LayeredListT m (s, x))
-> m (Either LoseOrCutfail ((s, x), LayeredListT m (s, x))))
-> Either LoseOrCutfail ((s, x), LayeredListT m (s, x))
-> m (Either LoseOrCutfail ((s, x), LayeredListT m (s, x)))
forall a b. (a -> b) -> a -> b
$ LoseOrCutfail
-> Either LoseOrCutfail ((s, x), LayeredListT m (s, x))
forall a b. a -> Either a b
Left LoseOrCutfail
failure
in
(LayeredListT m (s, x) -> ListT m (s, x)
forall (m :: * -> *) a. Monad m => LayeredListT m a -> ListT m a
fromLayeredListT (LayeredListT m (s, x) -> ListT m (s, x))
-> (ListT m x -> LayeredListT m (s, x))
-> ListT m x
-> ListT m (s, x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LayeredListT m x -> LayeredListT m (s, x)
listenStack (LayeredListT m x -> LayeredListT m (s, x))
-> (ListT m x -> LayeredListT m x)
-> ListT m x
-> LayeredListT m (s, x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ListT m x -> LayeredListT m x
forall (m :: * -> *) a. Monad m => ListT m a -> LayeredListT m a
toLayeredListT) (ListT m x -> ListT m (s, x)) -> ListT m x -> ListT m (s, x)
forall a b. (a -> b) -> a -> b
$ ListT m x
main
{-# INLINE threadEff #-}
instance Monoid s => ThreadsEff ListT (WriterPrim s) where
threadEff :: (forall x. WriterPrim s m x -> m x)
-> WriterPrim s (ListT m) a -> ListT m a
threadEff = ((forall x. WriterPrim s m x -> m x)
-> ListT m (s -> s, a) -> ListT m a)
-> (forall x. WriterPrim s m x -> m x)
-> WriterPrim s (ListT m) a
-> ListT m a
forall o (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, ThreadsEff t (ListenPrim o), Monad m) =>
((forall x. WriterPrim o m x -> m x) -> t m (o -> o, a) -> t m a)
-> (forall x. WriterPrim o m x -> m x)
-> WriterPrim o (t m) a
-> t m a
threadWriterPrim (((forall x. WriterPrim s m x -> m x)
-> ListT m (s -> s, a) -> ListT m a)
-> (forall x. WriterPrim s m x -> m x)
-> WriterPrim s (ListT m) a
-> ListT m a)
-> ((forall x. WriterPrim s m x -> m x)
-> ListT m (s -> s, a) -> ListT m a)
-> (forall x. WriterPrim s m x -> m x)
-> WriterPrim s (ListT m) a
-> ListT m a
forall a b. (a -> b) -> a -> b
$ \forall x. WriterPrim s m x -> m x
alg ListT m (s -> s, a)
main ->
let
passStack :: LayeredListT m (s -> s, a) -> LayeredListT m a
passStack LayeredListT m (s -> s, a)
m = m (Either LoseOrCutfail (a, LayeredListT m a)) -> LayeredListT m a
forall (m :: * -> *) a.
m (Either LoseOrCutfail (a, LayeredListT m a)) -> LayeredListT m a
LayeredListT (m (Either LoseOrCutfail (a, LayeredListT m a))
-> LayeredListT m a)
-> m (Either LoseOrCutfail (a, LayeredListT m a))
-> LayeredListT m a
forall a b. (a -> b) -> a -> b
$ WriterPrim s m (Either LoseOrCutfail (a, LayeredListT m a))
-> m (Either LoseOrCutfail (a, LayeredListT m a))
forall x. WriterPrim s m x -> m x
alg (WriterPrim s m (Either LoseOrCutfail (a, LayeredListT m a))
-> m (Either LoseOrCutfail (a, LayeredListT m a)))
-> WriterPrim s m (Either LoseOrCutfail (a, LayeredListT m a))
-> m (Either LoseOrCutfail (a, LayeredListT m a))
forall a b. (a -> b) -> a -> b
$ m (s -> s, Either LoseOrCutfail (a, LayeredListT m a))
-> WriterPrim s m (Either LoseOrCutfail (a, LayeredListT m a))
forall (m :: * -> *) o a. m (o -> o, a) -> WriterPrim o m a
WriterPrimPass (m (s -> s, Either LoseOrCutfail (a, LayeredListT m a))
-> WriterPrim s m (Either LoseOrCutfail (a, LayeredListT m a)))
-> m (s -> s, Either LoseOrCutfail (a, LayeredListT m a))
-> WriterPrim s m (Either LoseOrCutfail (a, LayeredListT m a))
forall a b. (a -> b) -> a -> b
$
LayeredListT m (s -> s, a)
-> m (Either
LoseOrCutfail ((s -> s, a), LayeredListT m (s -> s, a)))
forall (m :: * -> *) a.
LayeredListT m a -> m (Either LoseOrCutfail (a, LayeredListT m a))
unLayeredListT LayeredListT m (s -> s, a)
m m (Either LoseOrCutfail ((s -> s, a), LayeredListT m (s -> s, a)))
-> (Either LoseOrCutfail ((s -> s, a), LayeredListT m (s -> s, a))
-> m (s -> s, Either LoseOrCutfail (a, LayeredListT m a)))
-> m (s -> s, Either LoseOrCutfail (a, LayeredListT m a))
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Right ((s -> s
f, a
a), LayeredListT m (s -> s, a)
r) -> (s -> s, Either LoseOrCutfail (a, LayeredListT m a))
-> m (s -> s, Either LoseOrCutfail (a, LayeredListT m a))
forall (m :: * -> *) a. Monad m => a -> m a
return ((s -> s, Either LoseOrCutfail (a, LayeredListT m a))
-> m (s -> s, Either LoseOrCutfail (a, LayeredListT m a)))
-> (s -> s, Either LoseOrCutfail (a, LayeredListT m a))
-> m (s -> s, Either LoseOrCutfail (a, LayeredListT m a))
forall a b. (a -> b) -> a -> b
$ (s -> s
f, (a, LayeredListT m a) -> Either LoseOrCutfail (a, LayeredListT m a)
forall a b. b -> Either a b
Right (a
a, LayeredListT m (s -> s, a) -> LayeredListT m a
passStack LayeredListT m (s -> s, a)
r))
Left LoseOrCutfail
e -> (s -> s, Either LoseOrCutfail (a, LayeredListT m a))
-> m (s -> s, Either LoseOrCutfail (a, LayeredListT m a))
forall (m :: * -> *) a. Monad m => a -> m a
return ((s -> s, Either LoseOrCutfail (a, LayeredListT m a))
-> m (s -> s, Either LoseOrCutfail (a, LayeredListT m a)))
-> (s -> s, Either LoseOrCutfail (a, LayeredListT m a))
-> m (s -> s, Either LoseOrCutfail (a, LayeredListT m a))
forall a b. (a -> b) -> a -> b
$ (s -> s
forall a. a -> a
id, LoseOrCutfail -> Either LoseOrCutfail (a, LayeredListT m a)
forall a b. a -> Either a b
Left LoseOrCutfail
e)
in
(LayeredListT m a -> ListT m a
forall (m :: * -> *) a. Monad m => LayeredListT m a -> ListT m a
fromLayeredListT (LayeredListT m a -> ListT m a)
-> (ListT m (s -> s, a) -> LayeredListT m a)
-> ListT m (s -> s, a)
-> ListT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LayeredListT m (s -> s, a) -> LayeredListT m a
passStack (LayeredListT m (s -> s, a) -> LayeredListT m a)
-> (ListT m (s -> s, a) -> LayeredListT m (s -> s, a))
-> ListT m (s -> s, a)
-> LayeredListT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ListT m (s -> s, a) -> LayeredListT m (s -> s, a)
forall (m :: * -> *) a. Monad m => ListT m a -> LayeredListT m a
toLayeredListT) (ListT m (s -> s, a) -> ListT m a)
-> ListT m (s -> s, a) -> ListT m a
forall a b. (a -> b) -> a -> b
$ ListT m (s -> s, a)
main
{-# INLINE threadEff #-}
instance ThreadsEff ListT (ReaderPrim i) where
threadEff :: (forall x. ReaderPrim i m x -> m x)
-> ReaderPrim i (ListT m) a -> ListT m a
threadEff = (forall x. ReaderPrim i m x -> m x)
-> ReaderPrim i (ListT m) a -> ListT m a
forall i (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(Monad m, MonadTrans t, ThreadsEff t (Regional ())) =>
(forall x. ReaderPrim i m x -> m x)
-> ReaderPrim i (t m) a -> t m a
threadReaderPrimViaRegional
{-# INLINE threadEff #-}
instance MonadBase b m => MonadBase b (ListT m) where
liftBase :: b α -> ListT m α
liftBase = m α -> ListT m α
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m α -> ListT m α) -> (b α -> m α) -> b α -> ListT m α
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b α -> m α
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase
{-# INLINE liftBase #-}
instance Fail.MonadFail m => Fail.MonadFail (ListT m) where
fail :: String -> ListT m a
fail = m a -> ListT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ListT m a) -> (String -> m a) -> String -> ListT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
Fail.fail
{-# INLINE fail #-}
instance MonadThrow m => MonadThrow (ListT m) where
throwM :: e -> ListT m a
throwM = m a -> ListT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) 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 (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
C.throwM
{-# INLINE throwM #-}
instance MonadCatch m => MonadCatch (ListT m) where
catch :: ListT m a -> (e -> ListT m a) -> ListT m a
catch ListT m a
main e -> ListT m a
h = (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall (m :: * -> *) a.
(forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
ListT ((forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a)
-> (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall a b. (a -> b) -> a -> b
$ \a -> m r -> m r
c m r
b m r
t ->
let
n :: m (m r) -> m (m r)
n = (m (m r) -> (e -> m (m r)) -> m (m r)
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
`C.catch` \e
e -> m r -> m (m r)
forall (m :: * -> *) a. Monad m => a -> m a
return (m r -> m (m r)) -> m r -> m (m r)
forall a b. (a -> b) -> a -> b
$ ListT m a -> (a -> m r -> m r) -> m r -> m r -> m r
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT (e -> ListT m a
h e
e) a -> m r -> m r
c m r
b m r
t)
in
m (m r) -> m r
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (m (m r) -> m r) -> m (m r) -> m r
forall a b. (a -> b) -> a -> b
$ m (m r) -> m (m r)
n
(m (m r) -> m (m r)) -> m (m r) -> m (m r)
forall a b. (a -> b) -> a -> b
$ ListT m a
-> (a -> m (m r) -> m (m r)) -> m (m r) -> m (m r) -> m (m r)
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT ListT m a
main
(\a
a m (m r)
r -> m r -> m (m r)
forall (m :: * -> *) a. Monad m => a -> m a
return (m r -> m (m r)) -> m r -> m (m r)
forall a b. (a -> b) -> a -> b
$ a -> m r -> m r
c a
a (m (m r) -> m r
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (m (m r) -> m (m r)
n m (m r)
r)))
(m r -> m (m r)
forall (m :: * -> *) a. Monad m => a -> m a
return m r
b)
(m r -> m (m r)
forall (m :: * -> *) a. Monad m => a -> m a
return m r
t)
{-# INLINE catch #-}
cull :: ListT m a -> ListT m a
cull :: ListT m a -> ListT m a
cull ListT m a
m = (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall (m :: * -> *) a.
(forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
ListT ((forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a)
-> (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall a b. (a -> b) -> a -> b
$ \a -> m r -> m r
c m r
b m r
t -> ListT m a -> (a -> m r -> m r) -> m r -> m r -> m r
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT ListT m a
m (\a
a m r
_ -> a -> m r -> m r
c a
a m r
b) m r
b m r
t
choose :: ListT m a -> ListT m a -> ListT m a
choose :: ListT m a -> ListT m a -> ListT m a
choose ListT m a
ma ListT m a
mb = (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall (m :: * -> *) a.
(forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
ListT ((forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a)
-> (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall a b. (a -> b) -> a -> b
$ \a -> m r -> m r
c m r
b m r
t -> ListT m a -> (a -> m r -> m r) -> m r -> m r -> m r
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT ListT m a
ma a -> m r -> m r
c (ListT m a -> (a -> m r -> m r) -> m r -> m r -> m r
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT ListT m a
mb a -> m r -> m r
c m r
b m r
t) m r
t
lose :: ListT m a
lose :: ListT m a
lose = (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall (m :: * -> *) a.
(forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
ListT ((forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a)
-> (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall a b. (a -> b) -> a -> b
$ \a -> m r -> m r
_ m r
b m r
_ -> m r
b
cutfail :: ListT m a
cutfail :: ListT m a
cutfail = (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall (m :: * -> *) a.
(forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
ListT ((forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a)
-> (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall a b. (a -> b) -> a -> b
$ \a -> m r -> m r
_ m r
_ m r
t -> m r
t
call :: ListT m a -> ListT m a
call :: ListT m a -> ListT m a
call ListT m a
m = (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall (m :: * -> *) a.
(forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
ListT ((forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a)
-> (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall a b. (a -> b) -> a -> b
$ \a -> m r -> m r
c m r
b m r
_ -> ListT m a -> (a -> m r -> m r) -> m r -> m r -> m r
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT ListT m a
m a -> m r -> m r
c m r
b m r
b
data LoseOrCutfail
= Lost
| Cutfailed
newtype LayeredListT m a =
LayeredListT {
LayeredListT m a -> m (Either LoseOrCutfail (a, LayeredListT m a))
unLayeredListT :: m (Either LoseOrCutfail (a, LayeredListT m a))
}
toLayeredListT :: Monad m => ListT m a -> LayeredListT m a
toLayeredListT :: ListT m a -> LayeredListT m a
toLayeredListT ListT m a
main =
m (Either LoseOrCutfail (a, LayeredListT m a)) -> LayeredListT m a
forall (m :: * -> *) a.
m (Either LoseOrCutfail (a, LayeredListT m a)) -> LayeredListT m a
LayeredListT
(m (Either LoseOrCutfail (a, LayeredListT m a))
-> LayeredListT m a)
-> m (Either LoseOrCutfail (a, LayeredListT m a))
-> LayeredListT m a
forall a b. (a -> b) -> a -> b
$ ListT m a
-> (a
-> m (Either LoseOrCutfail (a, LayeredListT m a))
-> m (Either LoseOrCutfail (a, LayeredListT m a)))
-> m (Either LoseOrCutfail (a, LayeredListT m a))
-> m (Either LoseOrCutfail (a, LayeredListT m a))
-> m (Either LoseOrCutfail (a, LayeredListT m a))
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT ListT m a
main
(\a
a m (Either LoseOrCutfail (a, LayeredListT m a))
mr -> Either LoseOrCutfail (a, LayeredListT m a)
-> m (Either LoseOrCutfail (a, LayeredListT m a))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either LoseOrCutfail (a, LayeredListT m a)
-> m (Either LoseOrCutfail (a, LayeredListT m a)))
-> Either LoseOrCutfail (a, LayeredListT m a)
-> m (Either LoseOrCutfail (a, LayeredListT m a))
forall a b. (a -> b) -> a -> b
$ (a, LayeredListT m a) -> Either LoseOrCutfail (a, LayeredListT m a)
forall a b. b -> Either a b
Right ((a, LayeredListT m a)
-> Either LoseOrCutfail (a, LayeredListT m a))
-> (a, LayeredListT m a)
-> Either LoseOrCutfail (a, LayeredListT m a)
forall a b. (a -> b) -> a -> b
$ (a
a, m (Either LoseOrCutfail (a, LayeredListT m a)) -> LayeredListT m a
forall (m :: * -> *) a.
m (Either LoseOrCutfail (a, LayeredListT m a)) -> LayeredListT m a
LayeredListT m (Either LoseOrCutfail (a, LayeredListT m a))
mr))
(Either LoseOrCutfail (a, LayeredListT m a)
-> m (Either LoseOrCutfail (a, LayeredListT m a))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either LoseOrCutfail (a, LayeredListT m a)
-> m (Either LoseOrCutfail (a, LayeredListT m a)))
-> Either LoseOrCutfail (a, LayeredListT m a)
-> m (Either LoseOrCutfail (a, LayeredListT m a))
forall a b. (a -> b) -> a -> b
$ LoseOrCutfail -> Either LoseOrCutfail (a, LayeredListT m a)
forall a b. a -> Either a b
Left LoseOrCutfail
Lost)
(Either LoseOrCutfail (a, LayeredListT m a)
-> m (Either LoseOrCutfail (a, LayeredListT m a))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either LoseOrCutfail (a, LayeredListT m a)
-> m (Either LoseOrCutfail (a, LayeredListT m a)))
-> Either LoseOrCutfail (a, LayeredListT m a)
-> m (Either LoseOrCutfail (a, LayeredListT m a))
forall a b. (a -> b) -> a -> b
$ LoseOrCutfail -> Either LoseOrCutfail (a, LayeredListT m a)
forall a b. a -> Either a b
Left LoseOrCutfail
Cutfailed)
split' :: Monad m => LayeredListT m a -> LayeredListT m (Maybe (a, LayeredListT m a))
split' :: LayeredListT m a -> LayeredListT m (Maybe (a, LayeredListT m a))
split' LayeredListT m a
m = m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
-> LayeredListT m (Maybe (a, LayeredListT m a))
forall (m :: * -> *) a.
m (Either LoseOrCutfail (a, LayeredListT m a)) -> LayeredListT m a
LayeredListT (m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
-> LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
-> LayeredListT m (Maybe (a, LayeredListT m a))
forall a b. (a -> b) -> a -> b
$ LayeredListT m a -> m (Either LoseOrCutfail (a, LayeredListT m a))
forall (m :: * -> *) a.
LayeredListT m a -> m (Either LoseOrCutfail (a, LayeredListT m a))
unLayeredListT LayeredListT m a
m m (Either LoseOrCutfail (a, LayeredListT m a))
-> (Either LoseOrCutfail (a, LayeredListT m a)
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Right (a
a, LayeredListT m a
r) -> Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))))
-> Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
forall a b. (a -> b) -> a -> b
$ (Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
forall a b. b -> Either a b
Right ((a, LayeredListT m a) -> Maybe (a, LayeredListT m a)
forall a. a -> Maybe a
Just (a
a, LayeredListT m a
r), m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
-> LayeredListT m (Maybe (a, LayeredListT m a))
forall (m :: * -> *) a.
m (Either LoseOrCutfail (a, LayeredListT m a)) -> LayeredListT m a
LayeredListT (m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
-> LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
-> LayeredListT m (Maybe (a, LayeredListT m a))
forall a b. (a -> b) -> a -> b
$ Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))))
-> Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
forall a b. (a -> b) -> a -> b
$ LoseOrCutfail
-> Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
forall a b. a -> Either a b
Left LoseOrCutfail
Lost)
Left LoseOrCutfail
Lost -> Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))))
-> Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
forall a b. (a -> b) -> a -> b
$ (Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
forall a b. b -> Either a b
Right (Maybe (a, LayeredListT m a)
forall a. Maybe a
Nothing, m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
-> LayeredListT m (Maybe (a, LayeredListT m a))
forall (m :: * -> *) a.
m (Either LoseOrCutfail (a, LayeredListT m a)) -> LayeredListT m a
LayeredListT (m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
-> LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
-> LayeredListT m (Maybe (a, LayeredListT m a))
forall a b. (a -> b) -> a -> b
$ Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))))
-> Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
forall a b. (a -> b) -> a -> b
$ LoseOrCutfail
-> Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
forall a b. a -> Either a b
Left LoseOrCutfail
Lost)
Left LoseOrCutfail
Cutfailed -> Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))))
-> Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
-> m (Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a))))
forall a b. (a -> b) -> a -> b
$ LoseOrCutfail
-> Either
LoseOrCutfail
(Maybe (a, LayeredListT m a),
LayeredListT m (Maybe (a, LayeredListT m a)))
forall a b. a -> Either a b
Left LoseOrCutfail
Cutfailed
fromLayeredListT :: Monad m => LayeredListT m a -> ListT m a
fromLayeredListT :: LayeredListT m a -> ListT m a
fromLayeredListT LayeredListT m a
main = (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall (m :: * -> *) a.
(forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
ListT ((forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a)
-> (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall a b. (a -> b) -> a -> b
$ \a -> m r -> m r
c m r
b m r
t ->
let
go :: LayeredListT m a -> m r
go LayeredListT m a
m = LayeredListT m a -> m (Either LoseOrCutfail (a, LayeredListT m a))
forall (m :: * -> *) a.
LayeredListT m a -> m (Either LoseOrCutfail (a, LayeredListT m a))
unLayeredListT LayeredListT m a
m m (Either LoseOrCutfail (a, LayeredListT m a))
-> (Either LoseOrCutfail (a, LayeredListT m a) -> m r) -> m r
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Left LoseOrCutfail
Lost -> m r
b
Left LoseOrCutfail
Cutfailed -> m r
t
Right (a
a, LayeredListT m a
r) -> a -> m r -> m r
c a
a (LayeredListT m a -> m r
go LayeredListT m a
r)
in
LayeredListT m a -> m r
go LayeredListT m a
main
split :: Monad m => ListT m a -> ListT m (Maybe (a, ListT m a))
split :: ListT m a -> ListT m (Maybe (a, ListT m a))
split =
((Maybe (a, LayeredListT m a) -> Maybe (a, ListT m a))
-> ListT m (Maybe (a, LayeredListT m a))
-> ListT m (Maybe (a, ListT m a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Maybe (a, LayeredListT m a) -> Maybe (a, ListT m a))
-> ListT m (Maybe (a, LayeredListT m a))
-> ListT m (Maybe (a, ListT m a)))
-> ((LayeredListT m a -> ListT m a)
-> Maybe (a, LayeredListT m a) -> Maybe (a, ListT m a))
-> (LayeredListT m a -> ListT m a)
-> ListT m (Maybe (a, LayeredListT m a))
-> ListT m (Maybe (a, ListT m a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a, LayeredListT m a) -> (a, ListT m a))
-> Maybe (a, LayeredListT m a) -> Maybe (a, ListT m a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (((a, LayeredListT m a) -> (a, ListT m a))
-> Maybe (a, LayeredListT m a) -> Maybe (a, ListT m a))
-> ((LayeredListT m a -> ListT m a)
-> (a, LayeredListT m a) -> (a, ListT m a))
-> (LayeredListT m a -> ListT m a)
-> Maybe (a, LayeredListT m a)
-> Maybe (a, ListT m a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LayeredListT m a -> ListT m a)
-> (a, LayeredListT m a) -> (a, ListT m a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) LayeredListT m a -> ListT m a
forall (m :: * -> *) a. Monad m => LayeredListT m a -> ListT m a
fromLayeredListT
(ListT m (Maybe (a, LayeredListT m a))
-> ListT m (Maybe (a, ListT m a)))
-> (ListT m a -> ListT m (Maybe (a, LayeredListT m a)))
-> ListT m a
-> ListT m (Maybe (a, ListT m a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LayeredListT m (Maybe (a, LayeredListT m a))
-> ListT m (Maybe (a, LayeredListT m a))
forall (m :: * -> *) a. Monad m => LayeredListT m a -> ListT m a
fromLayeredListT
(LayeredListT m (Maybe (a, LayeredListT m a))
-> ListT m (Maybe (a, LayeredListT m a)))
-> (ListT m a -> LayeredListT m (Maybe (a, LayeredListT m a)))
-> ListT m a
-> ListT m (Maybe (a, LayeredListT m a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LayeredListT m a -> LayeredListT m (Maybe (a, LayeredListT m a))
forall (m :: * -> *) a.
Monad m =>
LayeredListT m a -> LayeredListT m (Maybe (a, LayeredListT m a))
split'
(LayeredListT m a -> LayeredListT m (Maybe (a, LayeredListT m a)))
-> (ListT m a -> LayeredListT m a)
-> ListT m a
-> LayeredListT m (Maybe (a, LayeredListT m a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ListT m a -> LayeredListT m a
forall (m :: * -> *) a. Monad m => ListT m a -> LayeredListT m a
toLayeredListT
{-# INLINE split #-}
instance Functor (ListT m) where
fmap :: (a -> b) -> ListT m a -> ListT m b
fmap a -> b
f ListT m a
m = (forall r. (b -> m r -> m r) -> m r -> m r -> m r) -> ListT m b
forall (m :: * -> *) a.
(forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
ListT ((forall r. (b -> m r -> m r) -> m r -> m r -> m r) -> ListT m b)
-> (forall r. (b -> m r -> m r) -> m r -> m r -> m r) -> ListT m b
forall a b. (a -> b) -> a -> b
$ \b -> m r -> m r
c m r
b m r
t ->
ListT m a -> (a -> m r -> m r) -> m r -> m r -> m r
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT ListT m a
m (b -> m r -> m r
c (b -> m r -> m r) -> (a -> b) -> a -> m r -> m r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f) m r
b m r
t
{-# INLINE fmap #-}
instance Applicative (ListT m) where
pure :: a -> ListT m a
pure a
a = (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall (m :: * -> *) a.
(forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
ListT ((forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a)
-> (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall a b. (a -> b) -> a -> b
$ \a -> m r -> m r
c m r
b m r
_ -> a -> m r -> m r
c a
a m r
b
liftA2 :: (a -> b -> c) -> ListT m a -> ListT m b -> ListT m c
liftA2 a -> b -> c
f ListT m a
fa ListT m b
fb = (forall r. (c -> m r -> m r) -> m r -> m r -> m r) -> ListT m c
forall (m :: * -> *) a.
(forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
ListT ((forall r. (c -> m r -> m r) -> m r -> m r -> m r) -> ListT m c)
-> (forall r. (c -> m r -> m r) -> m r -> m r -> m r) -> ListT m c
forall a b. (a -> b) -> a -> b
$ \c -> m r -> m r
c m r
b m r
t ->
ListT m a -> (a -> m r -> m r) -> m r -> m r -> m r
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT ListT m a
fa (\a
a m r
r -> ListT m b -> (b -> m r -> m r) -> m r -> m r -> m r
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT ListT m b
fb (c -> m r -> m r
c (c -> m r -> m r) -> (b -> c) -> b -> m r -> m r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b -> c
f a
a) m r
r m r
t) m r
b m r
t
{-# INLINE liftA2 #-}
ListT m a
ma *> :: ListT m a -> ListT m b -> ListT m b
*> ListT m b
mb = ListT m a
ma ListT m a -> (a -> ListT m b) -> ListT m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a
_ -> ListT m b
mb
{-# INLINE (*>) #-}
instance Monad (ListT m) where
ListT m a
m >>= :: ListT m a -> (a -> ListT m b) -> ListT m b
>>= a -> ListT m b
f = (forall r. (b -> m r -> m r) -> m r -> m r -> m r) -> ListT m b
forall (m :: * -> *) a.
(forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
ListT ((forall r. (b -> m r -> m r) -> m r -> m r -> m r) -> ListT m b)
-> (forall r. (b -> m r -> m r) -> m r -> m r -> m r) -> ListT m b
forall a b. (a -> b) -> a -> b
$ \b -> m r -> m r
c m r
b m r
t ->
ListT m a -> (a -> m r -> m r) -> m r -> m r -> m r
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT ListT m a
m (\a
a m r
r -> ListT m b -> (b -> m r -> m r) -> m r -> m r -> m r
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT (a -> ListT m b
f a
a) b -> m r -> m r
c m r
r m r
t) m r
b m r
t
{-# INLINE (>>=) #-}
instance MonadTrans ListT where
lift :: m a -> ListT m a
lift m a
m = (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall (m :: * -> *) a.
(forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
ListT ((forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a)
-> (forall r. (a -> m r -> m r) -> m r -> m r -> m r) -> ListT m a
forall a b. (a -> b) -> a -> b
$ \a -> m r -> m r
c m r
b m r
_ -> m a
m m a -> (a -> m r) -> m r
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (a -> m r -> m r
`c` m r
b)
{-# INLINE lift #-}
instance MonadIO m => MonadIO (ListT m) where
liftIO :: IO a -> ListT m a
liftIO = 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 (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
{-# INLINE liftIO #-}
runListT :: (Alternative f, Monad m)
=> ListT m a
-> m (f a)
runListT :: ListT m a -> m (f a)
runListT ListT m a
m =
ListT m a
-> (a -> m (f a) -> m (f a)) -> m (f a) -> m (f a) -> m (f a)
forall (m :: * -> *) a.
ListT m a -> forall r. (a -> m r -> m r) -> m r -> m r -> m r
unListT ListT m a
m ((f a -> f a) -> m (f a) -> m (f a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((f a -> f a) -> m (f a) -> m (f a))
-> (a -> f a -> f a) -> a -> m (f a) -> m (f a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> f a -> f a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
(<|>) (f a -> f a -> f a) -> (a -> f a) -> a -> f a -> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure) (f a -> m (f a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure f a
forall (f :: * -> *) a. Alternative f => f a
empty) (f a -> m (f a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure f a
forall (f :: * -> *) a. Alternative f => f a
empty)
{-# INLINE runListT #-}