{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ < 800
{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
#else
{-# OPTIONS_GHC -Wno-deprecations #-}
#endif
module Control.Monad.Trans.MSF.List
{-# WARNING "This module uses the ListT transformer, which is considered deprecated." #-}
( module Control.Monad.Trans.MSF.List
, module Control.Monad.Trans.List
)
where
#if !MIN_VERSION_base(4,8,0)
import Control.Applicative ((<$>))
#endif
import Control.Monad.Trans.List hiding (liftCallCC, liftCatch)
import Data.MonadicStreamFunction.InternalCore (MSF (MSF, unMSF))
widthFirst :: (Functor m, Monad m) => MSF (ListT m) a b -> MSF m a [b]
widthFirst :: forall (m :: * -> *) a b.
(Functor m, Monad m) =>
MSF (ListT m) a b -> MSF m a [b]
widthFirst MSF (ListT m) a b
msf = forall {m :: * -> *} {b} {a}.
Monad m =>
[MSF (ListT m) b a] -> MSF m b [a]
widthFirst' [MSF (ListT m) a b
msf]
where
widthFirst' :: [MSF (ListT m) b a] -> MSF m b [a]
widthFirst' [MSF (ListT m) b a]
msfs = forall (m :: * -> *) a b. (a -> m (b, MSF m a b)) -> MSF m a b
MSF forall a b. (a -> b) -> a -> b
$ \b
a -> do
([a]
bs, [MSF (ListT m) b a]
msfs') <- forall a b. [(a, b)] -> ([a], [b])
unzip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *) a. ListT m a -> m [a]
runListT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (m :: * -> *) a b. MSF m a b -> a -> m (b, MSF m a b)
unMSF b
a) [MSF (ListT m) b a]
msfs
forall (m :: * -> *) a. Monad m => a -> m a
return ([a]
bs, [MSF (ListT m) b a] -> MSF m b [a]
widthFirst' [MSF (ListT m) b a]
msfs')
sequenceS :: Monad m => [MSF m a b] -> MSF (ListT m) a b
sequenceS :: forall (m :: * -> *) a b.
Monad m =>
[MSF m a b] -> MSF (ListT m) a b
sequenceS [MSF m a b]
msfs = forall (m :: * -> *) a b. (a -> m (b, MSF m a b)) -> MSF m a b
MSF forall a b. (a -> b) -> a -> b
$ \a
a -> forall (m :: * -> *) a. m [a] -> ListT m a
ListT forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence forall a b. (a -> b) -> a -> b
$ forall {m :: * -> *} {a} {b}.
Monad m =>
a -> MSF m a b -> m (b, MSF (ListT m) a b)
apply a
a forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [MSF m a b]
msfs
where
apply :: a -> MSF m a b -> m (b, MSF (ListT m) a b)
apply a
a MSF m a b
msf = do
(b
b, MSF m a b
msf') <- forall (m :: * -> *) a b. MSF m a b -> a -> m (b, MSF m a b)
unMSF MSF m a b
msf a
a
forall (m :: * -> *) a. Monad m => a -> m a
return (b
b, forall (m :: * -> *) a b.
Monad m =>
[MSF m a b] -> MSF (ListT m) a b
sequenceS [MSF m a b
msf'])
mapMSF :: Monad m => MSF m a b -> MSF m [a] [b]
mapMSF :: forall (m :: * -> *) a b. Monad m => MSF m a b -> MSF m [a] [b]
mapMSF = forall (m :: * -> *) a b. (a -> m (b, MSF m a b)) -> MSF m a b
MSF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a t.
Monad m =>
MSF m a t -> [a] -> m ([t], MSF m [a] [t])
consume
where
consume :: Monad m => MSF m a t -> [a] -> m ([t], MSF m [a] [t])
consume :: forall (m :: * -> *) a t.
Monad m =>
MSF m a t -> [a] -> m ([t], MSF m [a] [t])
consume MSF m a t
sf [] = forall (m :: * -> *) a. Monad m => a -> m a
return ([], forall (m :: * -> *) a b. Monad m => MSF m a b -> MSF m [a] [b]
mapMSF MSF m a t
sf)
consume MSF m a t
sf (a
a:[a]
as) = do
(t
b, MSF m a t
sf') <- forall (m :: * -> *) a b. MSF m a b -> a -> m (b, MSF m a b)
unMSF MSF m a t
sf a
a
([t]
bs, MSF m [a] [t]
sf'') <- forall (m :: * -> *) a t.
Monad m =>
MSF m a t -> [a] -> m ([t], MSF m [a] [t])
consume MSF m a t
sf' [a]
as
t
b seq :: forall a b. a -> b -> b
`seq` forall (m :: * -> *) a. Monad m => a -> m a
return (t
bforall a. a -> [a] -> [a]
:[t]
bs, MSF m [a] [t]
sf'')