{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ViewPatterns #-}
module Data.Conduino.Lift (
stateP, runStateP, evalStateP, execStateP
, statePS, runStatePS, evalStatePS, execStatePS
, exceptP, runExceptP, runExceptP_
, readerP, runReaderP
, writerP, runWriterP, execWriterP
, writerPS, runWriterPS, execWriterPS
, rwsP, runRWSP, evalRWSP, execRWSP
, rwsPS, runRWSPS, evalRWSPS, execRWSPS
, catchP, runCatchP
) where
import Control.Monad.Catch.Pure
import Control.Monad.Trans.Class
import Control.Monad.Trans.Except
import Control.Monad.Trans.Free
import Control.Monad.Trans.RWS (RWST(..))
import Control.Monad.Trans.Reader
import Control.Monad.Trans.State
import Control.Monad.Trans.Writer
import Data.Conduino
import Data.Conduino.Internal
import Data.Functor
import qualified Control.Monad.Trans.RWS as RWS
import qualified Control.Monad.Trans.RWS.Strict as RWSS
import qualified Control.Monad.Trans.State.Strict as SS
import qualified Control.Monad.Trans.Writer.Strict as WS
stateP
:: Monad m
=> (s -> Pipe i o u m (a, s))
-> Pipe i o u (StateT s m) a
stateP :: (s -> Pipe i o u m (a, s)) -> Pipe i o u (StateT s m) a
stateP f :: s -> Pipe i o u m (a, s)
f = do
s
s <- StateT s m s -> Pipe i o u (StateT s m) s
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift StateT s m s
forall (m :: * -> *) s. Monad m => StateT s m s
get
(x :: a
x, s' :: s
s') <- (forall x. m x -> StateT s m x)
-> Pipe i o u m (a, s) -> Pipe i o u (StateT s m) (a, s)
forall (m :: * -> *) (n :: * -> *) i o u a.
(Monad m, Monad n) =>
(forall x. m x -> n x) -> Pipe i o u m a -> Pipe i o u n a
hoistPipe forall x. m x -> StateT s m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (s -> Pipe i o u m (a, s)
f s
s)
a
x a -> Pipe i o u (StateT s m) () -> Pipe i o u (StateT s m) a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ StateT s m () -> Pipe i o u (StateT s m) ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (s -> StateT s m ()
forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put s
s')
execStateP
:: Monad m
=> s
-> Pipe i o u (StateT s m) a
-> Pipe i o u m s
execStateP :: s -> Pipe i o u (StateT s m) a -> Pipe i o u m s
execStateP s :: s
s = ((a, s) -> s) -> Pipe i o u m (a, s) -> Pipe i o u m s
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a, s) -> s
forall a b. (a, b) -> b
snd (Pipe i o u m (a, s) -> Pipe i o u m s)
-> (Pipe i o u (StateT s m) a -> Pipe i o u m (a, s))
-> Pipe i o u (StateT s m) a
-> Pipe i o u m s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> Pipe i o u (StateT s m) a -> Pipe i o u m (a, s)
forall (m :: * -> *) s i o u a.
Monad m =>
s -> Pipe i o u (StateT s m) a -> Pipe i o u m (a, s)
runStateP s
s
evalStateP
:: Monad m
=> s
-> Pipe i o u (StateT s m) a
-> Pipe i o u m a
evalStateP :: s -> Pipe i o u (StateT s m) a -> Pipe i o u m a
evalStateP s :: s
s = ((a, s) -> a) -> Pipe i o u m (a, s) -> Pipe i o u m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a, s) -> a
forall a b. (a, b) -> a
fst (Pipe i o u m (a, s) -> Pipe i o u m a)
-> (Pipe i o u (StateT s m) a -> Pipe i o u m (a, s))
-> Pipe i o u (StateT s m) a
-> Pipe i o u m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> Pipe i o u (StateT s m) a -> Pipe i o u m (a, s)
forall (m :: * -> *) s i o u a.
Monad m =>
s -> Pipe i o u (StateT s m) a -> Pipe i o u m (a, s)
runStateP s
s
statePS
:: Monad m
=> (s -> Pipe i o u m (a, s))
-> Pipe i o u (SS.StateT s m) a
statePS :: (s -> Pipe i o u m (a, s)) -> Pipe i o u (StateT s m) a
statePS f :: s -> Pipe i o u m (a, s)
f = do
s
s <- StateT s m s -> Pipe i o u (StateT s m) s
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift StateT s m s
forall (m :: * -> *) s. Monad m => StateT s m s
SS.get
(x :: a
x, s' :: s
s') <- (forall x. m x -> StateT s m x)
-> Pipe i o u m (a, s) -> Pipe i o u (StateT s m) (a, s)
forall (m :: * -> *) (n :: * -> *) i o u a.
(Monad m, Monad n) =>
(forall x. m x -> n x) -> Pipe i o u m a -> Pipe i o u n a
hoistPipe forall x. m x -> StateT s m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (s -> Pipe i o u m (a, s)
f s
s)
a
x a -> Pipe i o u (StateT s m) () -> Pipe i o u (StateT s m) a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ StateT s m () -> Pipe i o u (StateT s m) ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (s -> StateT s m ()
forall (m :: * -> *) s. Monad m => s -> StateT s m ()
SS.put s
s')
runStatePS
:: Monad m
=> s
-> Pipe i o u (SS.StateT s m) a
-> Pipe i o u m (a, s)
runStatePS :: s -> Pipe i o u (StateT s m) a -> Pipe i o u m (a, s)
runStatePS = (RecPipe i o u (StateT s m) a -> RecPipe i o u m (a, s))
-> Pipe i o u (StateT s m) a -> Pipe i o u m (a, s)
forall (m :: * -> *) (n :: * -> *) i o u a j p v b.
(Monad m, Monad n) =>
(RecPipe i o u m a -> RecPipe j p v n b)
-> Pipe i o u m a -> Pipe j p v n b
withRecPipe ((RecPipe i o u (StateT s m) a -> RecPipe i o u m (a, s))
-> Pipe i o u (StateT s m) a -> Pipe i o u m (a, s))
-> (s -> RecPipe i o u (StateT s m) a -> RecPipe i o u m (a, s))
-> s
-> Pipe i o u (StateT s m) a
-> Pipe i o u m (a, s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> RecPipe i o u (StateT s m) a -> RecPipe i o u m (a, s)
forall (m :: * -> *) (f :: * -> *) t a.
(Functor m, Functor f) =>
t -> FreeT f (StateT t m) a -> FreeT f m (a, t)
go
where
go :: t -> FreeT f (StateT t m) a -> FreeT f m (a, t)
go s :: t
s (FreeT p :: StateT t m (FreeF f a (FreeT f (StateT t m) a))
p) = m (FreeF f (a, t) (FreeT f m (a, t))) -> FreeT f m (a, t)
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
FreeT (m (FreeF f (a, t) (FreeT f m (a, t))) -> FreeT f m (a, t))
-> m (FreeF f (a, t) (FreeT f m (a, t))) -> FreeT f m (a, t)
forall a b. (a -> b) -> a -> b
$ StateT t m (FreeF f a (FreeT f (StateT t m) a))
-> t -> m (FreeF f a (FreeT f (StateT t m) a), t)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
SS.runStateT StateT t m (FreeF f a (FreeT f (StateT t m) a))
p t
s m (FreeF f a (FreeT f (StateT t m) a), t)
-> ((FreeF f a (FreeT f (StateT t m) a), t)
-> FreeF f (a, t) (FreeT f m (a, t)))
-> m (FreeF f (a, t) (FreeT f m (a, t)))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(q :: FreeF f a (FreeT f (StateT t m) a)
q, s' :: t
s') ->
case FreeF f a (FreeT f (StateT t m) a)
q of
Pure x :: a
x -> (a, t) -> FreeF f (a, t) (FreeT f m (a, t))
forall (f :: * -> *) a b. a -> FreeF f a b
Pure (a
x, t
s')
Free l :: f (FreeT f (StateT t m) a)
l -> f (FreeT f m (a, t)) -> FreeF f (a, t) (FreeT f m (a, t))
forall (f :: * -> *) a b. f b -> FreeF f a b
Free (f (FreeT f m (a, t)) -> FreeF f (a, t) (FreeT f m (a, t)))
-> f (FreeT f m (a, t)) -> FreeF f (a, t) (FreeT f m (a, t))
forall a b. (a -> b) -> a -> b
$ t -> FreeT f (StateT t m) a -> FreeT f m (a, t)
go t
s' (FreeT f (StateT t m) a -> FreeT f m (a, t))
-> f (FreeT f (StateT t m) a) -> f (FreeT f m (a, t))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (FreeT f (StateT t m) a)
l
execStatePS
:: Monad m
=> s
-> Pipe i o u (SS.StateT s m) a
-> Pipe i o u m s
execStatePS :: s -> Pipe i o u (StateT s m) a -> Pipe i o u m s
execStatePS s :: s
s = ((a, s) -> s) -> Pipe i o u m (a, s) -> Pipe i o u m s
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a, s) -> s
forall a b. (a, b) -> b
snd (Pipe i o u m (a, s) -> Pipe i o u m s)
-> (Pipe i o u (StateT s m) a -> Pipe i o u m (a, s))
-> Pipe i o u (StateT s m) a
-> Pipe i o u m s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> Pipe i o u (StateT s m) a -> Pipe i o u m (a, s)
forall (m :: * -> *) s i o u a.
Monad m =>
s -> Pipe i o u (StateT s m) a -> Pipe i o u m (a, s)
runStatePS s
s
evalStatePS
:: Monad m
=> s
-> Pipe i o u (SS.StateT s m) a
-> Pipe i o u m a
evalStatePS :: s -> Pipe i o u (StateT s m) a -> Pipe i o u m a
evalStatePS s :: s
s = ((a, s) -> a) -> Pipe i o u m (a, s) -> Pipe i o u m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a, s) -> a
forall a b. (a, b) -> a
fst (Pipe i o u m (a, s) -> Pipe i o u m a)
-> (Pipe i o u (StateT s m) a -> Pipe i o u m (a, s))
-> Pipe i o u (StateT s m) a
-> Pipe i o u m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> Pipe i o u (StateT s m) a -> Pipe i o u m (a, s)
forall (m :: * -> *) s i o u a.
Monad m =>
s -> Pipe i o u (StateT s m) a -> Pipe i o u m (a, s)
runStatePS s
s
exceptP
:: Monad m
=> Pipe i o u m (Either e a)
-> Pipe i o u (ExceptT e m) a
exceptP :: Pipe i o u m (Either e a) -> Pipe i o u (ExceptT e m) a
exceptP p :: Pipe i o u m (Either e a)
p = (forall x. m x -> ExceptT e m x)
-> Pipe i o u m (Either e a)
-> Pipe i o u (ExceptT e m) (Either e a)
forall (m :: * -> *) (n :: * -> *) i o u a.
(Monad m, Monad n) =>
(forall x. m x -> n x) -> Pipe i o u m a -> Pipe i o u n a
hoistPipe forall x. m x -> ExceptT e m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Pipe i o u m (Either e a)
p Pipe i o u (ExceptT e m) (Either e a)
-> (Either e a -> Pipe i o u (ExceptT e m) a)
-> Pipe i o u (ExceptT e m) a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Left e :: e
e -> ExceptT e m a -> Pipe i o u (ExceptT e m) a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ExceptT e m a -> Pipe i o u (ExceptT e m) a)
-> ExceptT e m a -> Pipe i o u (ExceptT e m) a
forall a b. (a -> b) -> a -> b
$ e -> ExceptT e m a
forall (m :: * -> *) e a. Monad m => e -> ExceptT e m a
throwE e
e
Right x :: a
x -> a -> Pipe i o u (ExceptT e m) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x
runExceptP
:: Monad m
=> Pipe i o u (ExceptT e m) a
-> Pipe i o u m (Either e a)
runExceptP :: Pipe i o u (ExceptT e m) a -> Pipe i o u m (Either e a)
runExceptP = (RecPipe i o u (ExceptT e m) a -> RecPipe i o u m (Either e a))
-> Pipe i o u (ExceptT e m) a -> Pipe i o u m (Either e a)
forall (m :: * -> *) (n :: * -> *) i o u a j p v b.
(Monad m, Monad n) =>
(RecPipe i o u m a -> RecPipe j p v n b)
-> Pipe i o u m a -> Pipe j p v n b
withRecPipe RecPipe i o u (ExceptT e m) a -> RecPipe i o u m (Either e a)
forall (m :: * -> *) (f :: * -> *) a b.
(Functor m, Functor f) =>
FreeT f (ExceptT a m) b -> FreeT f m (Either a b)
go
where
go :: FreeT f (ExceptT a m) b -> FreeT f m (Either a b)
go (FreeT p :: ExceptT a m (FreeF f b (FreeT f (ExceptT a m) b))
p) = m (FreeF f (Either a b) (FreeT f m (Either a b)))
-> FreeT f m (Either a b)
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
FreeT (m (FreeF f (Either a b) (FreeT f m (Either a b)))
-> FreeT f m (Either a b))
-> m (FreeF f (Either a b) (FreeT f m (Either a b)))
-> FreeT f m (Either a b)
forall a b. (a -> b) -> a -> b
$ ExceptT a m (FreeF f b (FreeT f (ExceptT a m) b))
-> m (Either a (FreeF f b (FreeT f (ExceptT a m) b)))
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT ExceptT a m (FreeF f b (FreeT f (ExceptT a m) b))
p m (Either a (FreeF f b (FreeT f (ExceptT a m) b)))
-> (Either a (FreeF f b (FreeT f (ExceptT a m) b))
-> FreeF f (Either a b) (FreeT f m (Either a b)))
-> m (FreeF f (Either a b) (FreeT f m (Either a b)))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
Left e :: a
e -> Either a b -> FreeF f (Either a b) (FreeT f m (Either a b))
forall (f :: * -> *) a b. a -> FreeF f a b
Pure (Either a b -> FreeF f (Either a b) (FreeT f m (Either a b)))
-> Either a b -> FreeF f (Either a b) (FreeT f m (Either a b))
forall a b. (a -> b) -> a -> b
$ a -> Either a b
forall a b. a -> Either a b
Left a
e
Right (Pure x :: b
x) -> Either a b -> FreeF f (Either a b) (FreeT f m (Either a b))
forall (f :: * -> *) a b. a -> FreeF f a b
Pure (Either a b -> FreeF f (Either a b) (FreeT f m (Either a b)))
-> Either a b -> FreeF f (Either a b) (FreeT f m (Either a b))
forall a b. (a -> b) -> a -> b
$ b -> Either a b
forall a b. b -> Either a b
Right b
x
Right (Free l :: f (FreeT f (ExceptT a m) b)
l) -> f (FreeT f m (Either a b))
-> FreeF f (Either a b) (FreeT f m (Either a b))
forall (f :: * -> *) a b. f b -> FreeF f a b
Free (f (FreeT f m (Either a b))
-> FreeF f (Either a b) (FreeT f m (Either a b)))
-> f (FreeT f m (Either a b))
-> FreeF f (Either a b) (FreeT f m (Either a b))
forall a b. (a -> b) -> a -> b
$ FreeT f (ExceptT a m) b -> FreeT f m (Either a b)
go (FreeT f (ExceptT a m) b -> FreeT f m (Either a b))
-> f (FreeT f (ExceptT a m) b) -> f (FreeT f m (Either a b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (FreeT f (ExceptT a m) b)
l
runExceptP_
:: Monad m
=> Pipe i o u (ExceptT e m) a
-> Pipe i o u m ()
runExceptP_ :: Pipe i o u (ExceptT e m) a -> Pipe i o u m ()
runExceptP_ = Pipe i o u m (Either e a) -> Pipe i o u m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Pipe i o u m (Either e a) -> Pipe i o u m ())
-> (Pipe i o u (ExceptT e m) a -> Pipe i o u m (Either e a))
-> Pipe i o u (ExceptT e m) a
-> Pipe i o u m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pipe i o u (ExceptT e m) a -> Pipe i o u m (Either e a)
forall (m :: * -> *) i o u e a.
Monad m =>
Pipe i o u (ExceptT e m) a -> Pipe i o u m (Either e a)
runExceptP
catchP
:: Monad m
=> Pipe i o u m (Either SomeException a)
-> Pipe i o u (CatchT m) a
catchP :: Pipe i o u m (Either SomeException a) -> Pipe i o u (CatchT m) a
catchP p :: Pipe i o u m (Either SomeException a)
p = (forall x. m x -> CatchT m x)
-> Pipe i o u m (Either SomeException a)
-> Pipe i o u (CatchT m) (Either SomeException a)
forall (m :: * -> *) (n :: * -> *) i o u a.
(Monad m, Monad n) =>
(forall x. m x -> n x) -> Pipe i o u m a -> Pipe i o u n a
hoistPipe forall x. m x -> CatchT m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Pipe i o u m (Either SomeException a)
p Pipe i o u (CatchT m) (Either SomeException a)
-> (Either SomeException a -> Pipe i o u (CatchT m) a)
-> Pipe i o u (CatchT m) a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Left e :: SomeException
e -> CatchT m a -> Pipe i o u (CatchT m) a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (CatchT m a -> Pipe i o u (CatchT m) a)
-> CatchT m a -> Pipe i o u (CatchT m) a
forall a b. (a -> b) -> a -> b
$ SomeException -> CatchT m a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM SomeException
e
Right x :: a
x -> a -> Pipe i o u (CatchT m) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x
runCatchP
:: Monad m
=> Pipe i o u (CatchT m) a
-> Pipe i o u m (Either SomeException a)
runCatchP :: Pipe i o u (CatchT m) a -> Pipe i o u m (Either SomeException a)
runCatchP = (RecPipe i o u (CatchT m) a
-> RecPipe i o u m (Either SomeException a))
-> Pipe i o u (CatchT m) a -> Pipe i o u m (Either SomeException a)
forall (m :: * -> *) (n :: * -> *) i o u a j p v b.
(Monad m, Monad n) =>
(RecPipe i o u m a -> RecPipe j p v n b)
-> Pipe i o u m a -> Pipe j p v n b
withRecPipe RecPipe i o u (CatchT m) a
-> RecPipe i o u m (Either SomeException a)
forall (m :: * -> *) (f :: * -> *) b.
(Functor m, Functor f) =>
FreeT f (CatchT m) b -> FreeT f m (Either SomeException b)
go
where
go :: FreeT f (CatchT m) b -> FreeT f m (Either SomeException b)
go (FreeT p :: CatchT m (FreeF f b (FreeT f (CatchT m) b))
p) = m (FreeF
f (Either SomeException b) (FreeT f m (Either SomeException b)))
-> FreeT f m (Either SomeException b)
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
FreeT (m (FreeF
f (Either SomeException b) (FreeT f m (Either SomeException b)))
-> FreeT f m (Either SomeException b))
-> m (FreeF
f (Either SomeException b) (FreeT f m (Either SomeException b)))
-> FreeT f m (Either SomeException b)
forall a b. (a -> b) -> a -> b
$ CatchT m (FreeF f b (FreeT f (CatchT m) b))
-> m (Either SomeException (FreeF f b (FreeT f (CatchT m) b)))
forall (m :: * -> *) a. CatchT m a -> m (Either SomeException a)
runCatchT CatchT m (FreeF f b (FreeT f (CatchT m) b))
p m (Either SomeException (FreeF f b (FreeT f (CatchT m) b)))
-> (Either SomeException (FreeF f b (FreeT f (CatchT m) b))
-> FreeF
f (Either SomeException b) (FreeT f m (Either SomeException b)))
-> m (FreeF
f (Either SomeException b) (FreeT f m (Either SomeException b)))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
Left e :: SomeException
e -> Either SomeException b
-> FreeF
f (Either SomeException b) (FreeT f m (Either SomeException b))
forall (f :: * -> *) a b. a -> FreeF f a b
Pure (Either SomeException b
-> FreeF
f (Either SomeException b) (FreeT f m (Either SomeException b)))
-> Either SomeException b
-> FreeF
f (Either SomeException b) (FreeT f m (Either SomeException b))
forall a b. (a -> b) -> a -> b
$ SomeException -> Either SomeException b
forall a b. a -> Either a b
Left SomeException
e
Right (Pure x :: b
x) -> Either SomeException b
-> FreeF
f (Either SomeException b) (FreeT f m (Either SomeException b))
forall (f :: * -> *) a b. a -> FreeF f a b
Pure (Either SomeException b
-> FreeF
f (Either SomeException b) (FreeT f m (Either SomeException b)))
-> Either SomeException b
-> FreeF
f (Either SomeException b) (FreeT f m (Either SomeException b))
forall a b. (a -> b) -> a -> b
$ b -> Either SomeException b
forall a b. b -> Either a b
Right b
x
Right (Free l :: f (FreeT f (CatchT m) b)
l) -> f (FreeT f m (Either SomeException b))
-> FreeF
f (Either SomeException b) (FreeT f m (Either SomeException b))
forall (f :: * -> *) a b. f b -> FreeF f a b
Free (f (FreeT f m (Either SomeException b))
-> FreeF
f (Either SomeException b) (FreeT f m (Either SomeException b)))
-> f (FreeT f m (Either SomeException b))
-> FreeF
f (Either SomeException b) (FreeT f m (Either SomeException b))
forall a b. (a -> b) -> a -> b
$ FreeT f (CatchT m) b -> FreeT f m (Either SomeException b)
go (FreeT f (CatchT m) b -> FreeT f m (Either SomeException b))
-> f (FreeT f (CatchT m) b)
-> f (FreeT f m (Either SomeException b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (FreeT f (CatchT m) b)
l
readerP
:: Monad m
=> (r -> Pipe i o u m a)
-> Pipe i o u (ReaderT r m) a
readerP :: (r -> Pipe i o u m a) -> Pipe i o u (ReaderT r m) a
readerP f :: r -> Pipe i o u m a
f = (forall x. m x -> ReaderT r m x)
-> Pipe i o u m a -> Pipe i o u (ReaderT r m) a
forall (m :: * -> *) (n :: * -> *) i o u a.
(Monad m, Monad n) =>
(forall x. m x -> n x) -> Pipe i o u m a -> Pipe i o u n a
hoistPipe forall x. m x -> ReaderT r m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Pipe i o u m a -> Pipe i o u (ReaderT r m) a)
-> (r -> Pipe i o u m a) -> r -> Pipe i o u (ReaderT r m) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> Pipe i o u m a
f (r -> Pipe i o u (ReaderT r m) a)
-> Pipe i o u (ReaderT r m) r -> Pipe i o u (ReaderT r m) a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ReaderT r m r -> Pipe i o u (ReaderT r m) r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ReaderT r m r
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
runReaderP
:: Monad m
=> r
-> Pipe i o u (ReaderT r m) a
-> Pipe i o u m a
runReaderP :: r -> Pipe i o u (ReaderT r m) a -> Pipe i o u m a
runReaderP r :: r
r = (forall x. ReaderT r m x -> m x)
-> Pipe i o u (ReaderT r m) a -> Pipe i o u m a
forall (m :: * -> *) (n :: * -> *) i o u a.
(Monad m, Monad n) =>
(forall x. m x -> n x) -> Pipe i o u m a -> Pipe i o u n a
hoistPipe (ReaderT r m x -> r -> m x
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
`runReaderT` r
r)
writerP
:: (Monad m, Monoid w)
=> Pipe i o u m (a, w)
-> Pipe i o u (WriterT w m) a
writerP :: Pipe i o u m (a, w) -> Pipe i o u (WriterT w m) a
writerP p :: Pipe i o u m (a, w)
p = do
(x :: a
x, w :: w
w) <- (forall x. m x -> WriterT w m x)
-> Pipe i o u m (a, w) -> Pipe i o u (WriterT w m) (a, w)
forall (m :: * -> *) (n :: * -> *) i o u a.
(Monad m, Monad n) =>
(forall x. m x -> n x) -> Pipe i o u m a -> Pipe i o u n a
hoistPipe forall x. m x -> WriterT w m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Pipe i o u m (a, w)
p
a
x a -> Pipe i o u (WriterT w m) () -> Pipe i o u (WriterT w m) a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ WriterT w m () -> Pipe i o u (WriterT w m) ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (w -> WriterT w m ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
tell w
w)
runWriterP
:: (Monad m, Monoid w)
=> Pipe i o u (WriterT w m) a
-> Pipe i o u m (a, w)
runWriterP :: Pipe i o u (WriterT w m) a -> Pipe i o u m (a, w)
runWriterP = (RecPipe i o u (WriterT w m) a -> RecPipe i o u m (a, w))
-> Pipe i o u (WriterT w m) a -> Pipe i o u m (a, w)
forall (m :: * -> *) (n :: * -> *) i o u a j p v b.
(Monad m, Monad n) =>
(RecPipe i o u m a -> RecPipe j p v n b)
-> Pipe i o u m a -> Pipe j p v n b
withRecPipe (w -> RecPipe i o u (WriterT w m) a -> RecPipe i o u m (a, w)
forall t (m :: * -> *) (f :: * -> *) a.
(Semigroup t, Functor m, Functor f) =>
t -> FreeT f (WriterT t m) a -> FreeT f m (a, t)
go w
forall a. Monoid a => a
mempty)
where
go :: t -> FreeT f (WriterT t m) a -> FreeT f m (a, t)
go w :: t
w (FreeT p :: WriterT t m (FreeF f a (FreeT f (WriterT t m) a))
p) = m (FreeF f (a, t) (FreeT f m (a, t))) -> FreeT f m (a, t)
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
FreeT (m (FreeF f (a, t) (FreeT f m (a, t))) -> FreeT f m (a, t))
-> m (FreeF f (a, t) (FreeT f m (a, t))) -> FreeT f m (a, t)
forall a b. (a -> b) -> a -> b
$ WriterT t m (FreeF f a (FreeT f (WriterT t m) a))
-> m (FreeF f a (FreeT f (WriterT t m) a), t)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
runWriterT WriterT t m (FreeF f a (FreeT f (WriterT t m) a))
p m (FreeF f a (FreeT f (WriterT t m) a), t)
-> ((FreeF f a (FreeT f (WriterT t m) a), t)
-> FreeF f (a, t) (FreeT f m (a, t)))
-> m (FreeF f (a, t) (FreeT f m (a, t)))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(r :: FreeF f a (FreeT f (WriterT t m) a)
r, (t
w t -> t -> t
forall a. Semigroup a => a -> a -> a
<>)->t
w') ->
case FreeF f a (FreeT f (WriterT t m) a)
r of
Pure x :: a
x -> (a, t) -> FreeF f (a, t) (FreeT f m (a, t))
forall (f :: * -> *) a b. a -> FreeF f a b
Pure (a
x, t
w')
Free l :: f (FreeT f (WriterT t m) a)
l -> f (FreeT f m (a, t)) -> FreeF f (a, t) (FreeT f m (a, t))
forall (f :: * -> *) a b. f b -> FreeF f a b
Free (f (FreeT f m (a, t)) -> FreeF f (a, t) (FreeT f m (a, t)))
-> f (FreeT f m (a, t)) -> FreeF f (a, t) (FreeT f m (a, t))
forall a b. (a -> b) -> a -> b
$ t -> FreeT f (WriterT t m) a -> FreeT f m (a, t)
go t
w' (FreeT f (WriterT t m) a -> FreeT f m (a, t))
-> f (FreeT f (WriterT t m) a) -> f (FreeT f m (a, t))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (FreeT f (WriterT t m) a)
l
execWriterP
:: (Monad m, Monoid w)
=> Pipe i o u (WriterT w m) a
-> Pipe i o u m w
execWriterP :: Pipe i o u (WriterT w m) a -> Pipe i o u m w
execWriterP = ((a, w) -> w) -> Pipe i o u m (a, w) -> Pipe i o u m w
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a, w) -> w
forall a b. (a, b) -> b
snd (Pipe i o u m (a, w) -> Pipe i o u m w)
-> (Pipe i o u (WriterT w m) a -> Pipe i o u m (a, w))
-> Pipe i o u (WriterT w m) a
-> Pipe i o u m w
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pipe i o u (WriterT w m) a -> Pipe i o u m (a, w)
forall (m :: * -> *) w i o u a.
(Monad m, Monoid w) =>
Pipe i o u (WriterT w m) a -> Pipe i o u m (a, w)
runWriterP
writerPS
:: (Monad m, Monoid w)
=> Pipe i o u m (a, w)
-> Pipe i o u (WS.WriterT w m) a
writerPS :: Pipe i o u m (a, w) -> Pipe i o u (WriterT w m) a
writerPS p :: Pipe i o u m (a, w)
p = do
(x :: a
x, w :: w
w) <- (forall x. m x -> WriterT w m x)
-> Pipe i o u m (a, w) -> Pipe i o u (WriterT w m) (a, w)
forall (m :: * -> *) (n :: * -> *) i o u a.
(Monad m, Monad n) =>
(forall x. m x -> n x) -> Pipe i o u m a -> Pipe i o u n a
hoistPipe forall x. m x -> WriterT w m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Pipe i o u m (a, w)
p
a
x a -> Pipe i o u (WriterT w m) () -> Pipe i o u (WriterT w m) a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ WriterT w m () -> Pipe i o u (WriterT w m) ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (w -> WriterT w m ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
WS.tell w
w)
runWriterPS
:: (Monad m, Monoid w)
=> Pipe i o u (WS.WriterT w m) a
-> Pipe i o u m (a, w)
runWriterPS :: Pipe i o u (WriterT w m) a -> Pipe i o u m (a, w)
runWriterPS = (RecPipe i o u (WriterT w m) a -> RecPipe i o u m (a, w))
-> Pipe i o u (WriterT w m) a -> Pipe i o u m (a, w)
forall (m :: * -> *) (n :: * -> *) i o u a j p v b.
(Monad m, Monad n) =>
(RecPipe i o u m a -> RecPipe j p v n b)
-> Pipe i o u m a -> Pipe j p v n b
withRecPipe (w -> RecPipe i o u (WriterT w m) a -> RecPipe i o u m (a, w)
forall t (m :: * -> *) (f :: * -> *) a.
(Semigroup t, Functor m, Functor f) =>
t -> FreeT f (WriterT t m) a -> FreeT f m (a, t)
go w
forall a. Monoid a => a
mempty)
where
go :: t -> FreeT f (WriterT t m) a -> FreeT f m (a, t)
go w :: t
w (FreeT p :: WriterT t m (FreeF f a (FreeT f (WriterT t m) a))
p) = m (FreeF f (a, t) (FreeT f m (a, t))) -> FreeT f m (a, t)
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
FreeT (m (FreeF f (a, t) (FreeT f m (a, t))) -> FreeT f m (a, t))
-> m (FreeF f (a, t) (FreeT f m (a, t))) -> FreeT f m (a, t)
forall a b. (a -> b) -> a -> b
$ WriterT t m (FreeF f a (FreeT f (WriterT t m) a))
-> m (FreeF f a (FreeT f (WriterT t m) a), t)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
WS.runWriterT WriterT t m (FreeF f a (FreeT f (WriterT t m) a))
p m (FreeF f a (FreeT f (WriterT t m) a), t)
-> ((FreeF f a (FreeT f (WriterT t m) a), t)
-> FreeF f (a, t) (FreeT f m (a, t)))
-> m (FreeF f (a, t) (FreeT f m (a, t)))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(r :: FreeF f a (FreeT f (WriterT t m) a)
r, (t
w t -> t -> t
forall a. Semigroup a => a -> a -> a
<>)->t
w') ->
case FreeF f a (FreeT f (WriterT t m) a)
r of
Pure x :: a
x -> (a, t) -> FreeF f (a, t) (FreeT f m (a, t))
forall (f :: * -> *) a b. a -> FreeF f a b
Pure (a
x, t
w')
Free l :: f (FreeT f (WriterT t m) a)
l -> f (FreeT f m (a, t)) -> FreeF f (a, t) (FreeT f m (a, t))
forall (f :: * -> *) a b. f b -> FreeF f a b
Free (f (FreeT f m (a, t)) -> FreeF f (a, t) (FreeT f m (a, t)))
-> f (FreeT f m (a, t)) -> FreeF f (a, t) (FreeT f m (a, t))
forall a b. (a -> b) -> a -> b
$ t -> FreeT f (WriterT t m) a -> FreeT f m (a, t)
go t
w' (FreeT f (WriterT t m) a -> FreeT f m (a, t))
-> f (FreeT f (WriterT t m) a) -> f (FreeT f m (a, t))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (FreeT f (WriterT t m) a)
l
execWriterPS
:: (Monad m, Monoid w)
=> Pipe i o u (WriterT w m) a
-> Pipe i o u m w
execWriterPS :: Pipe i o u (WriterT w m) a -> Pipe i o u m w
execWriterPS = ((a, w) -> w) -> Pipe i o u m (a, w) -> Pipe i o u m w
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a, w) -> w
forall a b. (a, b) -> b
snd (Pipe i o u m (a, w) -> Pipe i o u m w)
-> (Pipe i o u (WriterT w m) a -> Pipe i o u m (a, w))
-> Pipe i o u (WriterT w m) a
-> Pipe i o u m w
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pipe i o u (WriterT w m) a -> Pipe i o u m (a, w)
forall (m :: * -> *) w i o u a.
(Monad m, Monoid w) =>
Pipe i o u (WriterT w m) a -> Pipe i o u m (a, w)
runWriterP
rwsP
:: (Monad m, Monoid w)
=> (r -> s -> Pipe i o u m (a, s, w))
-> Pipe i o u (RWST r w s m) a
rwsP :: (r -> s -> Pipe i o u m (a, s, w)) -> Pipe i o u (RWST r w s m) a
rwsP f :: r -> s -> Pipe i o u m (a, s, w)
f = do
r
r <- RWST r w s m r -> Pipe i o u (RWST r w s m) r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift RWST r w s m r
forall w (m :: * -> *) r s. (Monoid w, Monad m) => RWST r w s m r
RWS.ask
s
s <- RWST r w s m s -> Pipe i o u (RWST r w s m) s
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift RWST r w s m s
forall w (m :: * -> *) r s. (Monoid w, Monad m) => RWST r w s m s
RWS.get
(x :: a
x, s' :: s
s', w :: w
w) <- (forall x. m x -> RWST r w s m x)
-> Pipe i o u m (a, s, w) -> Pipe i o u (RWST r w s m) (a, s, w)
forall (m :: * -> *) (n :: * -> *) i o u a.
(Monad m, Monad n) =>
(forall x. m x -> n x) -> Pipe i o u m a -> Pipe i o u n a
hoistPipe forall x. m x -> RWST r w s m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (r -> s -> Pipe i o u m (a, s, w)
f r
r s
s)
RWST r w s m () -> Pipe i o u (RWST r w s m) ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (w -> RWST r w s m ()
forall (m :: * -> *) w r s. Monad m => w -> RWST r w s m ()
RWS.tell w
w)
a
x a -> Pipe i o u (RWST r w s m) () -> Pipe i o u (RWST r w s m) a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ RWST r w s m () -> Pipe i o u (RWST r w s m) ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (s -> RWST r w s m ()
forall w (m :: * -> *) s r.
(Monoid w, Monad m) =>
s -> RWST r w s m ()
RWS.put s
s')
runRWSP
:: (Monad m, Monoid w)
=> r
-> s
-> Pipe i o u (RWST r w s m) a
-> Pipe i o u m (a, s, w)
runRWSP :: r -> s -> Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w)
runRWSP r :: r
r = (RecPipe i o u (RWST r w s m) a -> RecPipe i o u m (a, s, w))
-> Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w)
forall (m :: * -> *) (n :: * -> *) i o u a j p v b.
(Monad m, Monad n) =>
(RecPipe i o u m a -> RecPipe j p v n b)
-> Pipe i o u m a -> Pipe j p v n b
withRecPipe ((RecPipe i o u (RWST r w s m) a -> RecPipe i o u m (a, s, w))
-> Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w))
-> (s
-> RecPipe i o u (RWST r w s m) a -> RecPipe i o u m (a, s, w))
-> s
-> Pipe i o u (RWST r w s m) a
-> Pipe i o u m (a, s, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. w
-> s -> RecPipe i o u (RWST r w s m) a -> RecPipe i o u m (a, s, w)
forall t (m :: * -> *) (f :: * -> *) t a.
(Semigroup t, Functor m, Functor f) =>
t -> t -> FreeT f (RWST r t t m) a -> FreeT f m (a, t, t)
go w
forall a. Monoid a => a
mempty
where
go :: t -> t -> FreeT f (RWST r t t m) a -> FreeT f m (a, t, t)
go w :: t
w s :: t
s (FreeT p :: RWST r t t m (FreeF f a (FreeT f (RWST r t t m) a))
p) = m (FreeF f (a, t, t) (FreeT f m (a, t, t))) -> FreeT f m (a, t, t)
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
FreeT (m (FreeF f (a, t, t) (FreeT f m (a, t, t)))
-> FreeT f m (a, t, t))
-> m (FreeF f (a, t, t) (FreeT f m (a, t, t)))
-> FreeT f m (a, t, t)
forall a b. (a -> b) -> a -> b
$ RWST r t t m (FreeF f a (FreeT f (RWST r t t m) a))
-> r -> t -> m (FreeF f a (FreeT f (RWST r t t m) a), t, t)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r t t m (FreeF f a (FreeT f (RWST r t t m) a))
p r
r t
s m (FreeF f a (FreeT f (RWST r t t m) a), t, t)
-> ((FreeF f a (FreeT f (RWST r t t m) a), t, t)
-> FreeF f (a, t, t) (FreeT f m (a, t, t)))
-> m (FreeF f (a, t, t) (FreeT f m (a, t, t)))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(q :: FreeF f a (FreeT f (RWST r t t m) a)
q, s' :: t
s', (t
w t -> t -> t
forall a. Semigroup a => a -> a -> a
<>)->t
w') ->
case FreeF f a (FreeT f (RWST r t t m) a)
q of
Pure x :: a
x -> (a, t, t) -> FreeF f (a, t, t) (FreeT f m (a, t, t))
forall (f :: * -> *) a b. a -> FreeF f a b
Pure (a
x, t
s', t
w')
Free l :: f (FreeT f (RWST r t t m) a)
l -> f (FreeT f m (a, t, t)) -> FreeF f (a, t, t) (FreeT f m (a, t, t))
forall (f :: * -> *) a b. f b -> FreeF f a b
Free (f (FreeT f m (a, t, t))
-> FreeF f (a, t, t) (FreeT f m (a, t, t)))
-> f (FreeT f m (a, t, t))
-> FreeF f (a, t, t) (FreeT f m (a, t, t))
forall a b. (a -> b) -> a -> b
$ t -> t -> FreeT f (RWST r t t m) a -> FreeT f m (a, t, t)
go t
w' t
s' (FreeT f (RWST r t t m) a -> FreeT f m (a, t, t))
-> f (FreeT f (RWST r t t m) a) -> f (FreeT f m (a, t, t))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (FreeT f (RWST r t t m) a)
l
evalRWSP
:: (Monad m, Monoid w)
=> r
-> s
-> Pipe i o u (RWST r w s m) a
-> Pipe i o u m (a, w)
evalRWSP :: r -> s -> Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, w)
evalRWSP r :: r
r s :: s
s = ((a, s, w) -> (a, w))
-> Pipe i o u m (a, s, w) -> Pipe i o u m (a, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(x :: a
x,_,w :: w
w) -> (a
x,w
w)) (Pipe i o u m (a, s, w) -> Pipe i o u m (a, w))
-> (Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w))
-> Pipe i o u (RWST r w s m) a
-> Pipe i o u m (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> s -> Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w)
forall (m :: * -> *) w r s i o u a.
(Monad m, Monoid w) =>
r -> s -> Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w)
runRWSP r
r s
s
execRWSP
:: (Monad m, Monoid w)
=> r
-> s
-> Pipe i o u (RWST r w s m) a
-> Pipe i o u m (s, w)
execRWSP :: r -> s -> Pipe i o u (RWST r w s m) a -> Pipe i o u m (s, w)
execRWSP r :: r
r s :: s
s = ((a, s, w) -> (s, w))
-> Pipe i o u m (a, s, w) -> Pipe i o u m (s, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(_,s' :: s
s',w :: w
w) -> (s
s',w
w)) (Pipe i o u m (a, s, w) -> Pipe i o u m (s, w))
-> (Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w))
-> Pipe i o u (RWST r w s m) a
-> Pipe i o u m (s, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> s -> Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w)
forall (m :: * -> *) w r s i o u a.
(Monad m, Monoid w) =>
r -> s -> Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w)
runRWSP r
r s
s
rwsPS
:: (Monad m, Monoid w)
=> (r -> s -> Pipe i o u m (a, s, w))
-> Pipe i o u (RWSS.RWST r w s m) a
rwsPS :: (r -> s -> Pipe i o u m (a, s, w)) -> Pipe i o u (RWST r w s m) a
rwsPS f :: r -> s -> Pipe i o u m (a, s, w)
f = do
r
r <- RWST r w s m r -> Pipe i o u (RWST r w s m) r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift RWST r w s m r
forall w (m :: * -> *) r s. (Monoid w, Monad m) => RWST r w s m r
RWSS.ask
s
s <- RWST r w s m s -> Pipe i o u (RWST r w s m) s
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift RWST r w s m s
forall w (m :: * -> *) r s. (Monoid w, Monad m) => RWST r w s m s
RWSS.get
(x :: a
x, s' :: s
s', w :: w
w) <- (forall x. m x -> RWST r w s m x)
-> Pipe i o u m (a, s, w) -> Pipe i o u (RWST r w s m) (a, s, w)
forall (m :: * -> *) (n :: * -> *) i o u a.
(Monad m, Monad n) =>
(forall x. m x -> n x) -> Pipe i o u m a -> Pipe i o u n a
hoistPipe forall x. m x -> RWST r w s m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (r -> s -> Pipe i o u m (a, s, w)
f r
r s
s)
RWST r w s m () -> Pipe i o u (RWST r w s m) ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (w -> RWST r w s m ()
forall (m :: * -> *) w r s. Monad m => w -> RWST r w s m ()
RWSS.tell w
w)
a
x a -> Pipe i o u (RWST r w s m) () -> Pipe i o u (RWST r w s m) a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ RWST r w s m () -> Pipe i o u (RWST r w s m) ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (s -> RWST r w s m ()
forall w (m :: * -> *) s r.
(Monoid w, Monad m) =>
s -> RWST r w s m ()
RWSS.put s
s')
runRWSPS
:: (Monad m, Monoid w)
=> r
-> s
-> Pipe i o u (RWSS.RWST r w s m) a
-> Pipe i o u m (a, s, w)
runRWSPS :: r -> s -> Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w)
runRWSPS r :: r
r = (RecPipe i o u (RWST r w s m) a -> RecPipe i o u m (a, s, w))
-> Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w)
forall (m :: * -> *) (n :: * -> *) i o u a j p v b.
(Monad m, Monad n) =>
(RecPipe i o u m a -> RecPipe j p v n b)
-> Pipe i o u m a -> Pipe j p v n b
withRecPipe ((RecPipe i o u (RWST r w s m) a -> RecPipe i o u m (a, s, w))
-> Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w))
-> (s
-> RecPipe i o u (RWST r w s m) a -> RecPipe i o u m (a, s, w))
-> s
-> Pipe i o u (RWST r w s m) a
-> Pipe i o u m (a, s, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. w
-> s -> RecPipe i o u (RWST r w s m) a -> RecPipe i o u m (a, s, w)
forall t (m :: * -> *) (f :: * -> *) t a.
(Semigroup t, Functor m, Functor f) =>
t -> t -> FreeT f (RWST r t t m) a -> FreeT f m (a, t, t)
go w
forall a. Monoid a => a
mempty
where
go :: t -> t -> FreeT f (RWST r t t m) a -> FreeT f m (a, t, t)
go w :: t
w s :: t
s (FreeT p :: RWST r t t m (FreeF f a (FreeT f (RWST r t t m) a))
p) = m (FreeF f (a, t, t) (FreeT f m (a, t, t))) -> FreeT f m (a, t, t)
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
FreeT (m (FreeF f (a, t, t) (FreeT f m (a, t, t)))
-> FreeT f m (a, t, t))
-> m (FreeF f (a, t, t) (FreeT f m (a, t, t)))
-> FreeT f m (a, t, t)
forall a b. (a -> b) -> a -> b
$ RWST r t t m (FreeF f a (FreeT f (RWST r t t m) a))
-> r -> t -> m (FreeF f a (FreeT f (RWST r t t m) a), t, t)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
RWSS.runRWST RWST r t t m (FreeF f a (FreeT f (RWST r t t m) a))
p r
r t
s m (FreeF f a (FreeT f (RWST r t t m) a), t, t)
-> ((FreeF f a (FreeT f (RWST r t t m) a), t, t)
-> FreeF f (a, t, t) (FreeT f m (a, t, t)))
-> m (FreeF f (a, t, t) (FreeT f m (a, t, t)))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(q :: FreeF f a (FreeT f (RWST r t t m) a)
q, s' :: t
s', (t
w t -> t -> t
forall a. Semigroup a => a -> a -> a
<>)->t
w') ->
case FreeF f a (FreeT f (RWST r t t m) a)
q of
Pure x :: a
x -> (a, t, t) -> FreeF f (a, t, t) (FreeT f m (a, t, t))
forall (f :: * -> *) a b. a -> FreeF f a b
Pure (a
x, t
s', t
w')
Free l :: f (FreeT f (RWST r t t m) a)
l -> f (FreeT f m (a, t, t)) -> FreeF f (a, t, t) (FreeT f m (a, t, t))
forall (f :: * -> *) a b. f b -> FreeF f a b
Free (f (FreeT f m (a, t, t))
-> FreeF f (a, t, t) (FreeT f m (a, t, t)))
-> f (FreeT f m (a, t, t))
-> FreeF f (a, t, t) (FreeT f m (a, t, t))
forall a b. (a -> b) -> a -> b
$ t -> t -> FreeT f (RWST r t t m) a -> FreeT f m (a, t, t)
go t
w' t
s' (FreeT f (RWST r t t m) a -> FreeT f m (a, t, t))
-> f (FreeT f (RWST r t t m) a) -> f (FreeT f m (a, t, t))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (FreeT f (RWST r t t m) a)
l
evalRWSPS
:: (Monad m, Monoid w)
=> r
-> s
-> Pipe i o u (RWSS.RWST r w s m) a
-> Pipe i o u m (a, w)
evalRWSPS :: r -> s -> Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, w)
evalRWSPS r :: r
r s :: s
s = ((a, s, w) -> (a, w))
-> Pipe i o u m (a, s, w) -> Pipe i o u m (a, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(x :: a
x,_,w :: w
w) -> (a
x,w
w)) (Pipe i o u m (a, s, w) -> Pipe i o u m (a, w))
-> (Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w))
-> Pipe i o u (RWST r w s m) a
-> Pipe i o u m (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> s -> Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w)
forall (m :: * -> *) w r s i o u a.
(Monad m, Monoid w) =>
r -> s -> Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w)
runRWSPS r
r s
s
execRWSPS
:: (Monad m, Monoid w)
=> r
-> s
-> Pipe i o u (RWSS.RWST r w s m) a
-> Pipe i o u m (s, w)
execRWSPS :: r -> s -> Pipe i o u (RWST r w s m) a -> Pipe i o u m (s, w)
execRWSPS r :: r
r s :: s
s = ((a, s, w) -> (s, w))
-> Pipe i o u m (a, s, w) -> Pipe i o u m (s, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(_,s' :: s
s',w :: w
w) -> (s
s',w
w)) (Pipe i o u m (a, s, w) -> Pipe i o u m (s, w))
-> (Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w))
-> Pipe i o u (RWST r w s m) a
-> Pipe i o u m (s, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> s -> Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w)
forall (m :: * -> *) w r s i o u a.
(Monad m, Monoid w) =>
r -> s -> Pipe i o u (RWST r w s m) a -> Pipe i o u m (a, s, w)
runRWSPS r
r s
s