{-# LANGUAGE CPP #-}
module Pipes.Lift (
distribute
, exceptP
, runExceptP
, catchError
, liftCatchError
, maybeP
, runMaybeP
, readerP
, runReaderP
, stateP
, runStateP
, evalStateP
, execStateP
, writerP
, runWriterP
, execWriterP
, rwsP
, runRWSP
, evalRWSP
, execRWSP
) where
import Control.Monad.Trans.Class (lift, MonadTrans(..))
import qualified Control.Monad.Trans.Except as E
import qualified Control.Monad.Trans.Maybe as M
import qualified Control.Monad.Trans.Reader as R
import qualified Control.Monad.Trans.State.Strict as S
import qualified Control.Monad.Trans.Writer.Strict as W
import qualified Control.Monad.Trans.RWS.Strict as RWS
import Pipes.Internal (Proxy(..), unsafeHoist)
import Control.Monad.Morph (hoist, MFunctor(..))
import Pipes.Core (runEffect, request, respond, (//>), (>\\))
#if MIN_VERSION_base(4,8,0)
#else
import Data.Monoid
#endif
distribute
:: ( Monad m
, MonadTrans t
, MFunctor t
, Monad (t m)
, Monad (t (Proxy a' a b' b m))
)
=> Proxy a' a b' b (t m) r
-> t (Proxy a' a b' b m) r
distribute :: Proxy a' a b' b (t m) r -> t (Proxy a' a b' b m) r
distribute Proxy a' a b' b (t m) r
p = Effect (t (Proxy a' a b' b m)) r -> t (Proxy a' a b' b m) r
forall (m :: * -> *) r. Monad m => Effect m r -> m r
runEffect (Effect (t (Proxy a' a b' b m)) r -> t (Proxy a' a b' b m) r)
-> Effect (t (Proxy a' a b' b m)) r -> t (Proxy a' a b' b m) r
forall a b. (a -> b) -> a -> b
$ a' -> Proxy X () b' b (t (Proxy a' a b' b m)) a
request' (a' -> Proxy X () b' b (t (Proxy a' a b' b m)) a)
-> Proxy a' a b' b (t (Proxy a' a b' b m)) r
-> Proxy X () b' b (t (Proxy a' a b' b m)) r
forall (m :: * -> *) b' a' a y' y b c.
Functor m =>
(b' -> Proxy a' a y' y m b)
-> Proxy b' b y' y m c -> Proxy a' a y' y m c
>\\ (forall x. t m x -> t (Proxy a' a b' b m) x)
-> Proxy a' a b' b (t m) r
-> Proxy a' a b' b (t (Proxy a' a b' b m)) r
forall (m :: * -> *) (n :: * -> *) a' a b' b r.
Functor m =>
(forall x. m x -> n x)
-> Proxy a' a b' b m r -> Proxy a' a b' b n r
unsafeHoist ((forall a. m a -> Proxy a' a b' b m a)
-> t m x -> t (Proxy a' a b' b m) x
forall k (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
(b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist forall a. m a -> Proxy a' a b' b m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift) Proxy a' a b' b (t m) r
p Proxy X () b' b (t (Proxy a' a b' b m)) r
-> (b -> Proxy X () () X (t (Proxy a' a b' b m)) b')
-> Effect (t (Proxy a' a b' b m)) r
forall (m :: * -> *) x' x b' b a' c' c.
Functor m =>
Proxy x' x b' b m a'
-> (b -> Proxy x' x c' c m b') -> Proxy x' x c' c m a'
//> b -> Proxy X () () X (t (Proxy a' a b' b m)) b'
respond'
where
request' :: a' -> Proxy X () b' b (t (Proxy a' a b' b m)) a
request' = t (Proxy a' a b' b m) a
-> Proxy X () b' b (t (Proxy a' a b' b m)) a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (t (Proxy a' a b' b m) a
-> Proxy X () b' b (t (Proxy a' a b' b m)) a)
-> (a' -> t (Proxy a' a b' b m) a)
-> a'
-> Proxy X () b' b (t (Proxy a' a b' b m)) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy a' a b' b m a -> t (Proxy a' a b' b m) a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Proxy a' a b' b m a -> t (Proxy a' a b' b m) a)
-> (a' -> Proxy a' a b' b m a) -> a' -> t (Proxy a' a b' b m) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a' -> Proxy a' a b' b m a
forall (m :: * -> *) a' a y' y.
Functor m =>
a' -> Proxy a' a y' y m a
request
respond' :: b -> Proxy X () () X (t (Proxy a' a b' b m)) b'
respond' = t (Proxy a' a b' b m) b'
-> Proxy X () () X (t (Proxy a' a b' b m)) b'
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (t (Proxy a' a b' b m) b'
-> Proxy X () () X (t (Proxy a' a b' b m)) b')
-> (b -> t (Proxy a' a b' b m) b')
-> b
-> Proxy X () () X (t (Proxy a' a b' b m)) b'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy a' a b' b m b' -> t (Proxy a' a b' b m) b'
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Proxy a' a b' b m b' -> t (Proxy a' a b' b m) b')
-> (b -> Proxy a' a b' b m b') -> b -> t (Proxy a' a b' b m) b'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Proxy a' a b' b m b'
forall (m :: * -> *) a x' x a'.
Functor m =>
a -> Proxy x' x a' a m a'
respond
{-# INLINABLE distribute #-}
exceptP
:: Monad m
=> Proxy a' a b' b m (Either e r)
-> Proxy a' a b' b (E.ExceptT e m) r
exceptP :: Proxy a' a b' b m (Either e r) -> Proxy a' a b' b (ExceptT e m) r
exceptP Proxy a' a b' b m (Either e r)
p = do
Either e r
x <- (forall x. m x -> ExceptT e m x)
-> Proxy a' a b' b m (Either e r)
-> Proxy a' a b' b (ExceptT e m) (Either e r)
forall (m :: * -> *) (n :: * -> *) a' a b' b r.
Functor m =>
(forall x. m x -> n x)
-> Proxy a' a b' b m r -> Proxy a' a b' b n r
unsafeHoist forall x. m x -> ExceptT e m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Proxy a' a b' b m (Either e r)
p
ExceptT e m r -> Proxy a' a b' b (ExceptT e m) r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ExceptT e m r -> Proxy a' a b' b (ExceptT e m) r)
-> ExceptT e m r -> Proxy a' a b' b (ExceptT e m) r
forall a b. (a -> b) -> a -> b
$ m (Either e r) -> ExceptT e m r
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
E.ExceptT (Either e r -> m (Either e r)
forall (m :: * -> *) a. Monad m => a -> m a
return Either e r
x)
{-# INLINABLE exceptP #-}
runExceptP
:: Monad m
=> Proxy a' a b' b (E.ExceptT e m) r
-> Proxy a' a b' b m (Either e r)
runExceptP :: Proxy a' a b' b (ExceptT e m) r -> Proxy a' a b' b m (Either e r)
runExceptP = ExceptT e (Proxy a' a b' b m) r -> Proxy a' a b' b m (Either e r)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
E.runExceptT (ExceptT e (Proxy a' a b' b m) r -> Proxy a' a b' b m (Either e r))
-> (Proxy a' a b' b (ExceptT e m) r
-> ExceptT e (Proxy a' a b' b m) r)
-> Proxy a' a b' b (ExceptT e m) r
-> Proxy a' a b' b m (Either e r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy a' a b' b (ExceptT e m) r -> ExceptT e (Proxy a' a b' b m) r
forall (m :: * -> *) (t :: (* -> *) -> * -> *) a' a b' b r.
(Monad m, MonadTrans t, MFunctor t, Monad (t m),
Monad (t (Proxy a' a b' b m))) =>
Proxy a' a b' b (t m) r -> t (Proxy a' a b' b m) r
distribute
{-# INLINABLE runExceptP #-}
catchError
:: Monad m
=> Proxy a' a b' b (E.ExceptT e m) r
-> (e -> Proxy a' a b' b (E.ExceptT e m) r)
-> Proxy a' a b' b (E.ExceptT e m) r
catchError :: Proxy a' a b' b (ExceptT e m) r
-> (e -> Proxy a' a b' b (ExceptT e m) r)
-> Proxy a' a b' b (ExceptT e m) r
catchError Proxy a' a b' b (ExceptT e m) r
e e -> Proxy a' a b' b (ExceptT e m) r
h = Proxy a' a b' b m (Either e r) -> Proxy a' a b' b (ExceptT e m) r
forall (m :: * -> *) a' a b' b e r.
Monad m =>
Proxy a' a b' b m (Either e r) -> Proxy a' a b' b (ExceptT e m) r
exceptP (Proxy a' a b' b m (Either e r) -> Proxy a' a b' b (ExceptT e m) r)
-> (ExceptT e (Proxy a' a b' b m) r
-> Proxy a' a b' b m (Either e r))
-> ExceptT e (Proxy a' a b' b m) r
-> Proxy a' a b' b (ExceptT e m) r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExceptT e (Proxy a' a b' b m) r -> Proxy a' a b' b m (Either e r)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
E.runExceptT (ExceptT e (Proxy a' a b' b m) r
-> Proxy a' a b' b (ExceptT e m) r)
-> ExceptT e (Proxy a' a b' b m) r
-> Proxy a' a b' b (ExceptT e m) r
forall a b. (a -> b) -> a -> b
$
ExceptT e (Proxy a' a b' b m) r
-> (e -> ExceptT e (Proxy a' a b' b m) r)
-> ExceptT e (Proxy a' a b' b m) r
forall (m :: * -> *) e a e'.
Monad m =>
ExceptT e m a -> (e -> ExceptT e' m a) -> ExceptT e' m a
E.catchE (Proxy a' a b' b (ExceptT e m) r -> ExceptT e (Proxy a' a b' b m) r
forall (m :: * -> *) (t :: (* -> *) -> * -> *) a' a b' b r.
(Monad m, MonadTrans t, MFunctor t, Monad (t m),
Monad (t (Proxy a' a b' b m))) =>
Proxy a' a b' b (t m) r -> t (Proxy a' a b' b m) r
distribute Proxy a' a b' b (ExceptT e m) r
e) (Proxy a' a b' b (ExceptT e m) r -> ExceptT e (Proxy a' a b' b m) r
forall (m :: * -> *) (t :: (* -> *) -> * -> *) a' a b' b r.
(Monad m, MonadTrans t, MFunctor t, Monad (t m),
Monad (t (Proxy a' a b' b m))) =>
Proxy a' a b' b (t m) r -> t (Proxy a' a b' b m) r
distribute (Proxy a' a b' b (ExceptT e m) r
-> ExceptT e (Proxy a' a b' b m) r)
-> (e -> Proxy a' a b' b (ExceptT e m) r)
-> e
-> ExceptT e (Proxy a' a b' b m) r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> Proxy a' a b' b (ExceptT e m) r
h)
{-# INLINABLE catchError #-}
liftCatchError
:: Monad m
=> ( m (Proxy a' a b' b m r)
-> (e -> m (Proxy a' a b' b m r))
-> m (Proxy a' a b' b m r) )
-> (Proxy a' a b' b m r
-> (e -> Proxy a' a b' b m r)
-> Proxy a' a b' b m r)
liftCatchError :: (m (Proxy a' a b' b m r)
-> (e -> m (Proxy a' a b' b m r)) -> m (Proxy a' a b' b m r))
-> Proxy a' a b' b m r
-> (e -> Proxy a' a b' b m r)
-> Proxy a' a b' b m r
liftCatchError m (Proxy a' a b' b m r)
-> (e -> m (Proxy a' a b' b m r)) -> m (Proxy a' a b' b m r)
c Proxy a' a b' b m r
p0 e -> Proxy a' a b' b m r
f = Proxy a' a b' b m r -> Proxy a' a b' b m r
go Proxy a' a b' b m r
p0
where
go :: Proxy a' a b' b m r -> Proxy a' a b' b m r
go Proxy a' a b' b m r
p = case Proxy a' a b' b m r
p of
Request a'
a' a -> Proxy a' a b' b m r
fa -> a' -> (a -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
forall a' a b' b (m :: * -> *) r.
a' -> (a -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
Request a'
a' (\a
a -> Proxy a' a b' b m r -> Proxy a' a b' b m r
go (a -> Proxy a' a b' b m r
fa a
a ))
Respond b
b b' -> Proxy a' a b' b m r
fb' -> b -> (b' -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
forall a' a b' b (m :: * -> *) r.
b -> (b' -> Proxy a' a b' b m r) -> Proxy a' a b' b m r
Respond b
b (\b'
b' -> Proxy a' a b' b m r -> Proxy a' a b' b m r
go (b' -> Proxy a' a b' b m r
fb' b'
b'))
Pure r
r -> r -> Proxy a' a b' b m r
forall a' a b' b (m :: * -> *) r. r -> Proxy a' a b' b m r
Pure r
r
M m (Proxy a' a b' b m r)
m -> m (Proxy a' a b' b m r) -> Proxy a' a b' b m r
forall a' a b' b (m :: * -> *) r.
m (Proxy a' a b' b m r) -> Proxy a' a b' b m r
M ((do
Proxy a' a b' b m r
p' <- m (Proxy a' a b' b m r)
m
Proxy a' a b' b m r -> m (Proxy a' a b' b m r)
forall (m :: * -> *) a. Monad m => a -> m a
return (Proxy a' a b' b m r -> Proxy a' a b' b m r
go Proxy a' a b' b m r
p') ) m (Proxy a' a b' b m r)
-> (e -> m (Proxy a' a b' b m r)) -> m (Proxy a' a b' b m r)
`c` (\e
e -> Proxy a' a b' b m r -> m (Proxy a' a b' b m r)
forall (m :: * -> *) a. Monad m => a -> m a
return (e -> Proxy a' a b' b m r
f e
e)) )
{-# INLINABLE liftCatchError #-}
maybeP
:: Monad m
=> Proxy a' a b' b m (Maybe r) -> Proxy a' a b' b (M.MaybeT m) r
maybeP :: Proxy a' a b' b m (Maybe r) -> Proxy a' a b' b (MaybeT m) r
maybeP Proxy a' a b' b m (Maybe r)
p = do
Maybe r
x <- (forall x. m x -> MaybeT m x)
-> Proxy a' a b' b m (Maybe r)
-> Proxy a' a b' b (MaybeT m) (Maybe r)
forall (m :: * -> *) (n :: * -> *) a' a b' b r.
Functor m =>
(forall x. m x -> n x)
-> Proxy a' a b' b m r -> Proxy a' a b' b n r
unsafeHoist forall x. m x -> MaybeT m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Proxy a' a b' b m (Maybe r)
p
MaybeT m r -> Proxy a' a b' b (MaybeT m) r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (MaybeT m r -> Proxy a' a b' b (MaybeT m) r)
-> MaybeT m r -> Proxy a' a b' b (MaybeT m) r
forall a b. (a -> b) -> a -> b
$ m (Maybe r) -> MaybeT m r
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
M.MaybeT (Maybe r -> m (Maybe r)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe r
x)
{-# INLINABLE maybeP #-}
runMaybeP
:: Monad m
=> Proxy a' a b' b (M.MaybeT m) r
-> Proxy a' a b' b m (Maybe r)
runMaybeP :: Proxy a' a b' b (MaybeT m) r -> Proxy a' a b' b m (Maybe r)
runMaybeP Proxy a' a b' b (MaybeT m) r
p = MaybeT (Proxy a' a b' b m) r -> Proxy a' a b' b m (Maybe r)
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
M.runMaybeT (MaybeT (Proxy a' a b' b m) r -> Proxy a' a b' b m (Maybe r))
-> MaybeT (Proxy a' a b' b m) r -> Proxy a' a b' b m (Maybe r)
forall a b. (a -> b) -> a -> b
$ Proxy a' a b' b (MaybeT m) r -> MaybeT (Proxy a' a b' b m) r
forall (m :: * -> *) (t :: (* -> *) -> * -> *) a' a b' b r.
(Monad m, MonadTrans t, MFunctor t, Monad (t m),
Monad (t (Proxy a' a b' b m))) =>
Proxy a' a b' b (t m) r -> t (Proxy a' a b' b m) r
distribute Proxy a' a b' b (MaybeT m) r
p
{-# INLINABLE runMaybeP #-}
readerP
:: Monad m
=> (i -> Proxy a' a b' b m r) -> Proxy a' a b' b (R.ReaderT i m) r
readerP :: (i -> Proxy a' a b' b m r) -> Proxy a' a b' b (ReaderT i m) r
readerP i -> Proxy a' a b' b m r
k = do
i
i <- ReaderT i m i -> Proxy a' a b' b (ReaderT i m) i
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ReaderT i m i
forall (m :: * -> *) r. Monad m => ReaderT r m r
R.ask
(forall x. m x -> ReaderT i m x)
-> Proxy a' a b' b m r -> Proxy a' a b' b (ReaderT i m) r
forall (m :: * -> *) (n :: * -> *) a' a b' b r.
Functor m =>
(forall x. m x -> n x)
-> Proxy a' a b' b m r -> Proxy a' a b' b n r
unsafeHoist forall x. m x -> ReaderT i m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (i -> Proxy a' a b' b m r
k i
i)
{-# INLINABLE readerP #-}
runReaderP
:: Monad m
=> i
-> Proxy a' a b' b (R.ReaderT i m) r
-> Proxy a' a b' b m r
runReaderP :: i -> Proxy a' a b' b (ReaderT i m) r -> Proxy a' a b' b m r
runReaderP i
r Proxy a' a b' b (ReaderT i m) r
p = (ReaderT i (Proxy a' a b' b m) r -> i -> Proxy a' a b' b m r
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
`R.runReaderT` i
r) (ReaderT i (Proxy a' a b' b m) r -> Proxy a' a b' b m r)
-> ReaderT i (Proxy a' a b' b m) r -> Proxy a' a b' b m r
forall a b. (a -> b) -> a -> b
$ Proxy a' a b' b (ReaderT i m) r -> ReaderT i (Proxy a' a b' b m) r
forall (m :: * -> *) (t :: (* -> *) -> * -> *) a' a b' b r.
(Monad m, MonadTrans t, MFunctor t, Monad (t m),
Monad (t (Proxy a' a b' b m))) =>
Proxy a' a b' b (t m) r -> t (Proxy a' a b' b m) r
distribute Proxy a' a b' b (ReaderT i m) r
p
{-# INLINABLE runReaderP #-}
stateP
:: Monad m
=> (s -> Proxy a' a b' b m (r, s)) -> Proxy a' a b' b (S.StateT s m) r
stateP :: (s -> Proxy a' a b' b m (r, s)) -> Proxy a' a b' b (StateT s m) r
stateP s -> Proxy a' a b' b m (r, s)
k = do
s
s <- StateT s m s -> Proxy a' a b' b (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
S.get
(r
r, s
s') <- (forall x. m x -> StateT s m x)
-> Proxy a' a b' b m (r, s) -> Proxy a' a b' b (StateT s m) (r, s)
forall (m :: * -> *) (n :: * -> *) a' a b' b r.
Functor m =>
(forall x. m x -> n x)
-> Proxy a' a b' b m r -> Proxy a' a b' b n r
unsafeHoist forall x. m x -> StateT s m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (s -> Proxy a' a b' b m (r, s)
k s
s)
StateT s m () -> Proxy a' a b' b (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 ()
S.put s
s')
r -> Proxy a' a b' b (StateT s m) r
forall (m :: * -> *) a. Monad m => a -> m a
return r
r
{-# INLINABLE stateP #-}
runStateP
:: Monad m
=> s
-> Proxy a' a b' b (S.StateT s m) r
-> Proxy a' a b' b m (r, s)
runStateP :: s -> Proxy a' a b' b (StateT s m) r -> Proxy a' a b' b m (r, s)
runStateP s
s Proxy a' a b' b (StateT s m) r
p = (StateT s (Proxy a' a b' b m) r -> s -> Proxy a' a b' b m (r, s)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
`S.runStateT` s
s) (StateT s (Proxy a' a b' b m) r -> Proxy a' a b' b m (r, s))
-> StateT s (Proxy a' a b' b m) r -> Proxy a' a b' b m (r, s)
forall a b. (a -> b) -> a -> b
$ Proxy a' a b' b (StateT s m) r -> StateT s (Proxy a' a b' b m) r
forall (m :: * -> *) (t :: (* -> *) -> * -> *) a' a b' b r.
(Monad m, MonadTrans t, MFunctor t, Monad (t m),
Monad (t (Proxy a' a b' b m))) =>
Proxy a' a b' b (t m) r -> t (Proxy a' a b' b m) r
distribute Proxy a' a b' b (StateT s m) r
p
{-# INLINABLE runStateP #-}
evalStateP
:: Monad m
=> s
-> Proxy a' a b' b (S.StateT s m) r
-> Proxy a' a b' b m r
evalStateP :: s -> Proxy a' a b' b (StateT s m) r -> Proxy a' a b' b m r
evalStateP s
s Proxy a' a b' b (StateT s m) r
p = ((r, s) -> r) -> Proxy a' a b' b m (r, s) -> Proxy a' a b' b m r
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (r, s) -> r
forall a b. (a, b) -> a
fst (Proxy a' a b' b m (r, s) -> Proxy a' a b' b m r)
-> Proxy a' a b' b m (r, s) -> Proxy a' a b' b m r
forall a b. (a -> b) -> a -> b
$ s -> Proxy a' a b' b (StateT s m) r -> Proxy a' a b' b m (r, s)
forall (m :: * -> *) s a' a b' b r.
Monad m =>
s -> Proxy a' a b' b (StateT s m) r -> Proxy a' a b' b m (r, s)
runStateP s
s Proxy a' a b' b (StateT s m) r
p
{-# INLINABLE evalStateP #-}
execStateP
:: Monad m
=> s
-> Proxy a' a b' b (S.StateT s m) r
-> Proxy a' a b' b m s
execStateP :: s -> Proxy a' a b' b (StateT s m) r -> Proxy a' a b' b m s
execStateP s
s Proxy a' a b' b (StateT s m) r
p = ((r, s) -> s) -> Proxy a' a b' b m (r, s) -> Proxy a' a b' b m s
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (r, s) -> s
forall a b. (a, b) -> b
snd (Proxy a' a b' b m (r, s) -> Proxy a' a b' b m s)
-> Proxy a' a b' b m (r, s) -> Proxy a' a b' b m s
forall a b. (a -> b) -> a -> b
$ s -> Proxy a' a b' b (StateT s m) r -> Proxy a' a b' b m (r, s)
forall (m :: * -> *) s a' a b' b r.
Monad m =>
s -> Proxy a' a b' b (StateT s m) r -> Proxy a' a b' b m (r, s)
runStateP s
s Proxy a' a b' b (StateT s m) r
p
{-# INLINABLE execStateP #-}
writerP
:: (Monad m, Monoid w)
=> Proxy a' a b' b m (r, w) -> Proxy a' a b' b (W.WriterT w m) r
writerP :: Proxy a' a b' b m (r, w) -> Proxy a' a b' b (WriterT w m) r
writerP Proxy a' a b' b m (r, w)
p = do
(r
r, w
w) <- (forall x. m x -> WriterT w m x)
-> Proxy a' a b' b m (r, w) -> Proxy a' a b' b (WriterT w m) (r, w)
forall (m :: * -> *) (n :: * -> *) a' a b' b r.
Functor m =>
(forall x. m x -> n x)
-> Proxy a' a b' b m r -> Proxy a' a b' b n r
unsafeHoist forall x. m x -> WriterT w m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Proxy a' a b' b m (r, w)
p
WriterT w m () -> Proxy a' a b' b (WriterT w m) ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (WriterT w m () -> Proxy a' a b' b (WriterT w m) ())
-> WriterT w m () -> Proxy a' a b' b (WriterT w m) ()
forall a b. (a -> b) -> a -> b
$ w -> WriterT w m ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell w
w
r -> Proxy a' a b' b (WriterT w m) r
forall (m :: * -> *) a. Monad m => a -> m a
return r
r
{-# INLINABLE writerP #-}
runWriterP
:: (Monad m, Monoid w)
=> Proxy a' a b' b (W.WriterT w m) r
-> Proxy a' a b' b m (r, w)
runWriterP :: Proxy a' a b' b (WriterT w m) r -> Proxy a' a b' b m (r, w)
runWriterP Proxy a' a b' b (WriterT w m) r
p = WriterT w (Proxy a' a b' b m) r -> Proxy a' a b' b m (r, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
W.runWriterT (WriterT w (Proxy a' a b' b m) r -> Proxy a' a b' b m (r, w))
-> WriterT w (Proxy a' a b' b m) r -> Proxy a' a b' b m (r, w)
forall a b. (a -> b) -> a -> b
$ Proxy a' a b' b (WriterT w m) r -> WriterT w (Proxy a' a b' b m) r
forall (m :: * -> *) (t :: (* -> *) -> * -> *) a' a b' b r.
(Monad m, MonadTrans t, MFunctor t, Monad (t m),
Monad (t (Proxy a' a b' b m))) =>
Proxy a' a b' b (t m) r -> t (Proxy a' a b' b m) r
distribute Proxy a' a b' b (WriterT w m) r
p
{-# INLINABLE runWriterP #-}
execWriterP
:: (Monad m, Monoid w)
=> Proxy a' a b' b (W.WriterT w m) r
-> Proxy a' a b' b m w
execWriterP :: Proxy a' a b' b (WriterT w m) r -> Proxy a' a b' b m w
execWriterP Proxy a' a b' b (WriterT w m) r
p = ((r, w) -> w) -> Proxy a' a b' b m (r, w) -> Proxy a' a b' b m w
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (r, w) -> w
forall a b. (a, b) -> b
snd (Proxy a' a b' b m (r, w) -> Proxy a' a b' b m w)
-> Proxy a' a b' b m (r, w) -> Proxy a' a b' b m w
forall a b. (a -> b) -> a -> b
$ Proxy a' a b' b (WriterT w m) r -> Proxy a' a b' b m (r, w)
forall (m :: * -> *) w a' a b' b r.
(Monad m, Monoid w) =>
Proxy a' a b' b (WriterT w m) r -> Proxy a' a b' b m (r, w)
runWriterP Proxy a' a b' b (WriterT w m) r
p
{-# INLINABLE execWriterP #-}
rwsP
:: (Monad m, Monoid w)
=> (i -> s -> Proxy a' a b' b m (r, s, w))
-> Proxy a' a b' b (RWS.RWST i w s m) r
rwsP :: (i -> s -> Proxy a' a b' b m (r, s, w))
-> Proxy a' a b' b (RWST i w s m) r
rwsP i -> s -> Proxy a' a b' b m (r, s, w)
k = do
i
i <- RWST i w s m i -> Proxy a' a b' b (RWST i w s m) i
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift RWST i w s m i
forall w (m :: * -> *) r s. (Monoid w, Monad m) => RWST r w s m r
RWS.ask
s
s <- RWST i w s m s -> Proxy a' a b' b (RWST i w s m) s
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift RWST i w s m s
forall w (m :: * -> *) r s. (Monoid w, Monad m) => RWST r w s m s
RWS.get
(r
r, s
s', w
w) <- (forall x. m x -> RWST i w s m x)
-> Proxy a' a b' b m (r, s, w)
-> Proxy a' a b' b (RWST i w s m) (r, s, w)
forall (m :: * -> *) (n :: * -> *) a' a b' b r.
Functor m =>
(forall x. m x -> n x)
-> Proxy a' a b' b m r -> Proxy a' a b' b n r
unsafeHoist forall x. m x -> RWST i w s m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (i -> s -> Proxy a' a b' b m (r, s, w)
k i
i s
s)
RWST i w s m () -> Proxy a' a b' b (RWST i w s m) ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (RWST i w s m () -> Proxy a' a b' b (RWST i w s m) ())
-> RWST i w s m () -> Proxy a' a b' b (RWST i w s m) ()
forall a b. (a -> b) -> a -> b
$ do
s -> RWST i w s m ()
forall w (m :: * -> *) s r.
(Monoid w, Monad m) =>
s -> RWST r w s m ()
RWS.put s
s'
w -> RWST i w s m ()
forall (m :: * -> *) w r s. Monad m => w -> RWST r w s m ()
RWS.tell w
w
r -> Proxy a' a b' b (RWST i w s m) r
forall (m :: * -> *) a. Monad m => a -> m a
return r
r
{-# INLINABLE rwsP #-}
runRWSP
:: (Monad m, Monoid w)
=> r
-> s
-> Proxy a' a b' b (RWS.RWST r w s m) d
-> Proxy a' a b' b m (d, s, w)
runRWSP :: r
-> s
-> Proxy a' a b' b (RWST r w s m) d
-> Proxy a' a b' b m (d, s, w)
runRWSP r
i s
s Proxy a' a b' b (RWST r w s m) d
p = (\RWST r w s (Proxy a' a b' b m) d
b -> RWST r w s (Proxy a' a b' b m) d
-> r -> s -> Proxy a' a b' b m (d, s, w)
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
RWS.runRWST RWST r w s (Proxy a' a b' b m) d
b r
i s
s) (RWST r w s (Proxy a' a b' b m) d -> Proxy a' a b' b m (d, s, w))
-> RWST r w s (Proxy a' a b' b m) d -> Proxy a' a b' b m (d, s, w)
forall a b. (a -> b) -> a -> b
$ Proxy a' a b' b (RWST r w s m) d
-> RWST r w s (Proxy a' a b' b m) d
forall (m :: * -> *) (t :: (* -> *) -> * -> *) a' a b' b r.
(Monad m, MonadTrans t, MFunctor t, Monad (t m),
Monad (t (Proxy a' a b' b m))) =>
Proxy a' a b' b (t m) r -> t (Proxy a' a b' b m) r
distribute Proxy a' a b' b (RWST r w s m) d
p
{-# INLINABLE runRWSP #-}
evalRWSP
:: (Monad m, Monoid w)
=> r
-> s
-> Proxy a' a b' b (RWS.RWST r w s m) d
-> Proxy a' a b' b m (d, w)
evalRWSP :: r
-> s
-> Proxy a' a b' b (RWST r w s m) d
-> Proxy a' a b' b m (d, w)
evalRWSP r
i s
s Proxy a' a b' b (RWST r w s m) d
p = ((d, s, w) -> (d, w))
-> Proxy a' a b' b m (d, s, w) -> Proxy a' a b' b m (d, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (d, s, w) -> (d, w)
forall a b b. (a, b, b) -> (a, b)
f (Proxy a' a b' b m (d, s, w) -> Proxy a' a b' b m (d, w))
-> Proxy a' a b' b m (d, s, w) -> Proxy a' a b' b m (d, w)
forall a b. (a -> b) -> a -> b
$ r
-> s
-> Proxy a' a b' b (RWST r w s m) d
-> Proxy a' a b' b m (d, s, w)
forall (m :: * -> *) w r s a' a b' b d.
(Monad m, Monoid w) =>
r
-> s
-> Proxy a' a b' b (RWST r w s m) d
-> Proxy a' a b' b m (d, s, w)
runRWSP r
i s
s Proxy a' a b' b (RWST r w s m) d
p
where
f :: (a, b, b) -> (a, b)
f (a, b, b)
x = let (a
r, b
_, b
w) = (a, b, b)
x in (a
r, b
w)
{-# INLINABLE evalRWSP #-}
execRWSP
:: (Monad m, Monoid w)
=> r
-> s
-> Proxy a' a b' b (RWS.RWST r w s m) d
-> Proxy a' a b' b m (s, w)
execRWSP :: r
-> s
-> Proxy a' a b' b (RWST r w s m) d
-> Proxy a' a b' b m (s, w)
execRWSP r
i s
s Proxy a' a b' b (RWST r w s m) d
p = ((d, s, w) -> (s, w))
-> Proxy a' a b' b m (d, s, w) -> Proxy a' a b' b m (s, w)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (d, s, w) -> (s, w)
forall a a b. (a, a, b) -> (a, b)
f (Proxy a' a b' b m (d, s, w) -> Proxy a' a b' b m (s, w))
-> Proxy a' a b' b m (d, s, w) -> Proxy a' a b' b m (s, w)
forall a b. (a -> b) -> a -> b
$ r
-> s
-> Proxy a' a b' b (RWST r w s m) d
-> Proxy a' a b' b m (d, s, w)
forall (m :: * -> *) w r s a' a b' b d.
(Monad m, Monoid w) =>
r
-> s
-> Proxy a' a b' b (RWST r w s m) d
-> Proxy a' a b' b m (d, s, w)
runRWSP r
i s
s Proxy a' a b' b (RWST r w s m) d
p
where
f :: (a, a, b) -> (a, b)
f (a, a, b)
x = let (a
_, a
s', b
w) = (a, a, b)
x in (a
s', b
w)
{-# INLINABLE execRWSP #-}