{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE Trustworthy #-}
module Pipes.Internal (
Proxy(..)
, unsafeHoist
, observe
, X
, closed
) where
import qualified Control.Monad.Fail as F (MonadFail(fail))
import Control.Monad.IO.Class (MonadIO(liftIO))
import Control.Monad.Trans.Class (MonadTrans(lift))
import Control.Monad.Morph (MFunctor(hoist), MMonad(embed))
import Control.Monad.Except (MonadError(..))
import Control.Monad.Catch (MonadThrow(..), MonadCatch(..))
import Control.Monad.Reader (MonadReader(..))
import Control.Monad.State (MonadState(..))
import Control.Monad.Writer (MonadWriter(..), censor)
import Data.Void (Void)
#if MIN_VERSION_base(4,8,0)
import Control.Applicative (Alternative(..))
#else
import Control.Applicative
#endif
import Data.Semigroup
import qualified Data.Void
data Proxy a' a b' b m r
= Request a' (a -> Proxy a' a b' b m r )
| Respond b (b' -> Proxy a' a b' b m r )
| M (m (Proxy a' a b' b m r))
| Pure r
instance Functor m => Functor (Proxy a' a b' b m) where
fmap :: (a -> b) -> Proxy a' a b' b m a -> Proxy a' a b' b m b
fmap a -> b
f Proxy a' a b' b m a
p0 = Proxy a' a b' b m a -> Proxy a' a b' b m b
forall (m :: * -> *) a' a b' b.
Functor m =>
Proxy a' a b' b m a -> Proxy a' a b' b m b
go Proxy a' a b' b m a
p0 where
go :: Proxy a' a b' b m a -> Proxy a' a b' b m b
go Proxy a' a b' b m a
p = case Proxy a' a b' b m a
p of
Request a'
a' a -> Proxy a' a b' b m a
fa -> a' -> (a -> Proxy a' a b' b m b) -> Proxy a' a b' b m b
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 a -> Proxy a' a b' b m b
go (a -> Proxy a' a b' b m a
fa a
a ))
Respond b
b b' -> Proxy a' a b' b m a
fb' -> b -> (b' -> Proxy a' a b' b m b) -> Proxy a' a b' b m b
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 a -> Proxy a' a b' b m b
go (b' -> Proxy a' a b' b m a
fb' b'
b'))
M m (Proxy a' a b' b m a)
m -> m (Proxy a' a b' b m b) -> Proxy a' a b' b m b
forall a' a b' b (m :: * -> *) r.
m (Proxy a' a b' b m r) -> Proxy a' a b' b m r
M (Proxy a' a b' b m a -> Proxy a' a b' b m b
go (Proxy a' a b' b m a -> Proxy a' a b' b m b)
-> m (Proxy a' a b' b m a) -> m (Proxy a' a b' b m b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Proxy a' a b' b m a)
m)
Pure a
r -> b -> Proxy a' a b' b m b
forall a' a b' b (m :: * -> *) r. r -> Proxy a' a b' b m r
Pure (a -> b
f a
r)
instance Functor m => Applicative (Proxy a' a b' b m) where
pure :: a -> Proxy a' a b' b m a
pure = a -> Proxy a' a b' b m a
forall a' a b' b (m :: * -> *) r. r -> Proxy a' a b' b m r
Pure
Proxy a' a b' b m (a -> b)
pf <*> :: Proxy a' a b' b m (a -> b)
-> Proxy a' a b' b m a -> Proxy a' a b' b m b
<*> Proxy a' a b' b m a
px = Proxy a' a b' b m (a -> b) -> Proxy a' a b' b m b
forall r. Proxy a' a b' b m (a -> r) -> Proxy a' a b' b m r
go Proxy a' a b' b m (a -> b)
pf where
go :: Proxy a' a b' b m (a -> r) -> Proxy a' a b' b m r
go Proxy a' a b' b m (a -> r)
p = case Proxy a' a b' b m (a -> r)
p of
Request a'
a' a -> Proxy a' a b' b m (a -> 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 (a -> r) -> Proxy a' a b' b m r
go (a -> Proxy a' a b' b m (a -> r)
fa a
a ))
Respond b
b b' -> Proxy a' a b' b m (a -> 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 (a -> r) -> Proxy a' a b' b m r
go (b' -> Proxy a' a b' b m (a -> r)
fb' b'
b'))
M m (Proxy a' a b' b m (a -> 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 (Proxy a' a b' b m (a -> r) -> Proxy a' a b' b m r
go (Proxy a' a b' b m (a -> r) -> Proxy a' a b' b m r)
-> m (Proxy a' a b' b m (a -> r)) -> m (Proxy a' a b' b m r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Proxy a' a b' b m (a -> r))
m)
Pure a -> r
f -> (a -> r) -> Proxy a' a b' b m a -> Proxy a' a b' b m r
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> r
f Proxy a' a b' b m a
px
Proxy a' a b' b m a
l *> :: Proxy a' a b' b m a -> Proxy a' a b' b m b -> Proxy a' a b' b m b
*> Proxy a' a b' b m b
r = Proxy a' a b' b m a -> Proxy a' a b' b m b
forall r. Proxy a' a b' b m r -> Proxy a' a b' b m b
go Proxy a' a b' b m a
l where
go :: Proxy a' a b' b m r -> Proxy a' a b' b m b
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 b) -> Proxy a' a b' b m b
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 b
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 b) -> Proxy a' a b' b m b
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 b
go (b' -> Proxy a' a b' b m r
fb' b'
b'))
M m (Proxy a' a b' b m r)
m -> m (Proxy a' a b' b m b) -> Proxy a' a b' b m b
forall a' a b' b (m :: * -> *) r.
m (Proxy a' a b' b m r) -> Proxy a' a b' b m r
M (Proxy a' a b' b m r -> Proxy a' a b' b m b
go (Proxy a' a b' b m r -> Proxy a' a b' b m b)
-> m (Proxy a' a b' b m r) -> m (Proxy a' a b' b m b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Proxy a' a b' b m r)
m)
Pure r
_ -> Proxy a' a b' b m b
r
instance Functor m => Monad (Proxy a' a b' b m) where
return :: a -> Proxy a' a b' b m a
return = a -> Proxy a' a b' b m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
>>= :: Proxy a' a b' b m a
-> (a -> Proxy a' a b' b m b) -> Proxy a' a b' b m b
(>>=) = Proxy a' a b' b m a
-> (a -> Proxy a' a b' b m b) -> Proxy a' a b' b m b
forall (m :: * -> *) a' a b' b r r'.
Functor m =>
Proxy a' a b' b m r
-> (r -> Proxy a' a b' b m r') -> Proxy a' a b' b m r'
_bind
_bind
:: Functor m
=> Proxy a' a b' b m r
-> (r -> Proxy a' a b' b m r')
-> Proxy a' a b' b m r'
Proxy a' a b' b m r
p0 _bind :: Proxy a' a b' b m r
-> (r -> Proxy a' a b' b m r') -> Proxy a' a b' b m r'
`_bind` r -> 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'))
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 (Proxy a' a b' b m r -> Proxy a' a b' b m r'
go (Proxy a' a b' b m r -> Proxy a' a b' b m r')
-> m (Proxy a' a b' b m r) -> m (Proxy a' a b' b m r')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Proxy a' a b' b m r)
m)
Pure r
r -> r -> Proxy a' a b' b m r'
f r
r
{-# NOINLINE[1] _bind #-}
{-# RULES
"_bind (Request a' k) f" forall a' k f .
_bind (Request a' k) f = Request a' (\a -> _bind (k a) f);
"_bind (Respond b k) f" forall b k f .
_bind (Respond b k) f = Respond b (\b' -> _bind (k b') f);
"_bind (M m) f" forall m f .
_bind (M m) f = M ((\p -> _bind p f) <$> m);
"_bind (Pure r ) f" forall r f .
_bind (Pure r ) f = f r;
#-}
instance (Functor m, Semigroup r) => Semigroup (Proxy a' a b' b m r) where
Proxy a' a b' b m r
p1 <> :: Proxy a' a b' b m r -> Proxy a' a b' b m r -> Proxy a' a b' b m r
<> Proxy a' a b' b m r
p2 = Proxy a' a b' b m r -> Proxy a' a b' b m r
go Proxy a' a b' b m r
p1 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'))
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 (Proxy a' a b' b m r -> Proxy a' a b' b m r
go (Proxy a' a b' b m r -> Proxy a' a b' b m r)
-> m (Proxy a' a b' b m r) -> m (Proxy a' a b' b m r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Proxy a' a b' b m r)
m)
Pure r
r1 -> (r -> r) -> Proxy a' a b' b m r -> Proxy a' a b' b m r
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (r
r1 r -> r -> r
forall a. Semigroup a => a -> a -> a
<>) Proxy a' a b' b m r
p2
instance (Functor m, Monoid r, Semigroup r) => Monoid (Proxy a' a b' b m r) where
mempty :: Proxy a' a b' b m r
mempty = 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
forall a. Monoid a => a
mempty
#if !(MIN_VERSION_base(4,11,0))
mappend = (<>)
#endif
instance MonadTrans (Proxy a' a b' b) where
lift :: m a -> Proxy a' a b' b m a
lift m a
m = m (Proxy a' a b' b m a) -> Proxy a' a b' b m a
forall a' a b' b (m :: * -> *) r.
m (Proxy a' a b' b m r) -> Proxy a' a b' b m r
M (a -> Proxy a' a b' b m a
forall a' a b' b (m :: * -> *) r. r -> Proxy a' a b' b m r
Pure (a -> Proxy a' a b' b m a) -> m a -> m (Proxy a' a b' b m a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
m)
unsafeHoist
:: 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 -> n x)
-> Proxy a' a b' b m r -> Proxy a' a b' b n r
unsafeHoist forall x. m x -> n x
nat = Proxy a' a b' b m r -> Proxy a' a b' b n r
forall a' a b' b r. Proxy a' a b' b m r -> Proxy a' a b' b n r
go
where
go :: Proxy a' a b' b m r -> Proxy a' a b' b n 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 n r) -> Proxy a' a b' b n 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 n 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 n r) -> Proxy a' a b' b n 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 n r
go (b' -> Proxy a' a b' b m r
fb' b'
b'))
M m (Proxy a' a b' b m r)
m -> n (Proxy a' a b' b n r) -> Proxy a' a b' b n r
forall a' a b' b (m :: * -> *) r.
m (Proxy a' a b' b m r) -> Proxy a' a b' b m r
M (m (Proxy a' a b' b n r) -> n (Proxy a' a b' b n r)
forall x. m x -> n x
nat (Proxy a' a b' b m r -> Proxy a' a b' b n r
go (Proxy a' a b' b m r -> Proxy a' a b' b n r)
-> m (Proxy a' a b' b m r) -> m (Proxy a' a b' b n r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Proxy a' a b' b m r)
m))
Pure r
r -> r -> Proxy a' a b' b n r
forall a' a b' b (m :: * -> *) r. r -> Proxy a' a b' b m r
Pure r
r
{-# INLINABLE unsafeHoist #-}
instance MFunctor (Proxy a' a b' b) where
hoist :: (forall a. m a -> n a)
-> Proxy a' a b' b m b -> Proxy a' a b' b n b
hoist forall a. m a -> n a
nat Proxy a' a b' b m b
p0 = Proxy a' a b' b m b -> Proxy a' a b' b n b
forall a' a b' b r. Proxy a' a b' b m r -> Proxy a' a b' b n r
go (Proxy a' a b' b m b -> Proxy a' a b' b m b
forall (m :: * -> *) a' a b' b r.
Monad m =>
Proxy a' a b' b m r -> Proxy a' a b' b m r
observe Proxy a' a b' b m b
p0)
where
go :: Proxy a' a b' b m r -> Proxy a' a b' b n 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 n r) -> Proxy a' a b' b n 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 n 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 n r) -> Proxy a' a b' b n 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 n r
go (b' -> Proxy a' a b' b m r
fb' b'
b'))
M m (Proxy a' a b' b m r)
m -> n (Proxy a' a b' b n r) -> Proxy a' a b' b n r
forall a' a b' b (m :: * -> *) r.
m (Proxy a' a b' b m r) -> Proxy a' a b' b m r
M (m (Proxy a' a b' b n r) -> n (Proxy a' a b' b n r)
forall a. m a -> n a
nat (Proxy a' a b' b m r -> Proxy a' a b' b n r
go (Proxy a' a b' b m r -> Proxy a' a b' b n r)
-> m (Proxy a' a b' b m r) -> m (Proxy a' a b' b n r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Proxy a' a b' b m r)
m))
Pure r
r -> r -> Proxy a' a b' b n r
forall a' a b' b (m :: * -> *) r. r -> Proxy a' a b' b m r
Pure r
r
instance MMonad (Proxy a' a b' b) where
embed :: (forall a. m a -> Proxy a' a b' b n a)
-> Proxy a' a b' b m b -> Proxy a' a b' b n b
embed forall a. m a -> Proxy a' a b' b n a
f = Proxy a' a b' b m b -> Proxy a' a b' b n b
forall b. Proxy a' a b' b m b -> Proxy a' a b' b n b
go
where
go :: Proxy a' a b' b m b -> Proxy a' a b' b n b
go Proxy a' a b' b m b
p = case Proxy a' a b' b m b
p of
Request a'
a' a -> Proxy a' a b' b m b
fa -> a' -> (a -> Proxy a' a b' b n b) -> Proxy a' a b' b n b
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 b -> Proxy a' a b' b n b
go (a -> Proxy a' a b' b m b
fa a
a ))
Respond b
b b' -> Proxy a' a b' b m b
fb' -> b -> (b' -> Proxy a' a b' b n b) -> Proxy a' a b' b n b
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 b -> Proxy a' a b' b n b
go (b' -> Proxy a' a b' b m b
fb' b'
b'))
M m (Proxy a' a b' b m b)
m -> m (Proxy a' a b' b m b) -> Proxy a' a b' b n (Proxy a' a b' b m b)
forall a. m a -> Proxy a' a b' b n a
f m (Proxy a' a b' b m b)
m Proxy a' a b' b n (Proxy a' a b' b m b)
-> (Proxy a' a b' b m b -> Proxy a' a b' b n b)
-> Proxy a' a b' b n b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Proxy a' a b' b m b -> Proxy a' a b' b n b
go
Pure b
r -> b -> Proxy a' a b' b n b
forall a' a b' b (m :: * -> *) r. r -> Proxy a' a b' b m r
Pure b
r
instance F.MonadFail m => F.MonadFail (Proxy a' a b' b m) where
fail :: String -> Proxy a' a b' b m a
fail = m a -> Proxy a' a b' b m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> Proxy a' a b' b m a)
-> (String -> m a) -> String -> Proxy a' a b' b m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
F.fail
instance MonadIO m => MonadIO (Proxy a' a b' b m) where
liftIO :: IO a -> Proxy a' a b' b m a
liftIO IO a
m = m (Proxy a' a b' b m a) -> Proxy a' a b' b m a
forall a' a b' b (m :: * -> *) r.
m (Proxy a' a b' b m r) -> Proxy a' a b' b m r
M (IO (Proxy a' a b' b m a) -> m (Proxy a' a b' b m a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (a -> Proxy a' a b' b m a
forall a' a b' b (m :: * -> *) r. r -> Proxy a' a b' b m r
Pure (a -> Proxy a' a b' b m a) -> IO a -> IO (Proxy a' a b' b m a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO a
m))
instance MonadReader r m => MonadReader r (Proxy a' a b' b m) where
ask :: Proxy a' a b' b m r
ask = m r -> Proxy a' a b' b m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m r
forall r (m :: * -> *). MonadReader r m => m r
ask
local :: (r -> r) -> Proxy a' a b' b m a -> Proxy a' a b' b m a
local r -> r
f = Proxy a' a b' b m a -> Proxy a' a b' b m a
forall (m :: * -> *) a' a b' b r.
MonadReader r m =>
Proxy a' a b' b m r -> Proxy a' a b' b m r
go
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 (Proxy a' a b' b m r -> Proxy a' a b' b m r
go (Proxy a' a b' b m r -> Proxy a' a b' b m r)
-> m (Proxy a' a b' b m r) -> m (Proxy a' a b' b m r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (r -> r) -> m (Proxy a' a b' b m r) -> m (Proxy a' a b' b m r)
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local r -> r
f m (Proxy a' a b' b m r)
m)
reader :: (r -> a) -> Proxy a' a b' b m a
reader = m a -> Proxy a' a b' b m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> Proxy a' a b' b m a)
-> ((r -> a) -> m a) -> (r -> a) -> Proxy a' a b' b m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r -> a) -> m a
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
reader
instance MonadState s m => MonadState s (Proxy a' a b' b m) where
get :: Proxy a' a b' b m s
get = m s -> Proxy a' a b' b m s
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m s
forall s (m :: * -> *). MonadState s m => m s
get
put :: s -> Proxy a' a b' b m ()
put = m () -> Proxy a' a b' b m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> Proxy a' a b' b m ())
-> (s -> m ()) -> s -> Proxy a' a b' b m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put
state :: (s -> (a, s)) -> Proxy a' a b' b m a
state = m a -> Proxy a' a b' b m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> Proxy a' a b' b m a)
-> ((s -> (a, s)) -> m a) -> (s -> (a, s)) -> Proxy a' a b' b m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (s -> (a, s)) -> m a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state
instance MonadWriter w m => MonadWriter w (Proxy a' a b' b m) where
writer :: (a, w) -> Proxy a' a b' b m a
writer = m a -> Proxy a' a b' b m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> Proxy a' a b' b m a)
-> ((a, w) -> m a) -> (a, w) -> Proxy a' a b' b m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, w) -> m a
forall w (m :: * -> *) a. MonadWriter w m => (a, w) -> m a
writer
tell :: w -> Proxy a' a b' b m ()
tell = m () -> Proxy a' a b' b m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> Proxy a' a b' b m ())
-> (w -> m ()) -> w -> Proxy a' a b' b m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. w -> m ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell
listen :: Proxy a' a b' b m a -> Proxy a' a b' b m (a, w)
listen Proxy a' a b' b m a
p0 = Proxy a' a b' b m a -> w -> Proxy a' a b' b m (a, w)
forall (m :: * -> *) b a' a b' b a.
MonadWriter b m =>
Proxy a' a b' b m a -> b -> Proxy a' a b' b m (a, b)
go Proxy a' a b' b m a
p0 w
forall a. Monoid a => a
mempty
where
go :: Proxy a' a b' b m a -> b -> Proxy a' a b' b m (a, b)
go Proxy a' a b' b m a
p b
w = case Proxy a' a b' b m a
p of
Request a'
a' a -> Proxy a' a b' b m a
fa -> a' -> (a -> Proxy a' a b' b m (a, b)) -> Proxy a' a b' b m (a, b)
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 a -> b -> Proxy a' a b' b m (a, b)
go (a -> Proxy a' a b' b m a
fa a
a ) b
w)
Respond b
b b' -> Proxy a' a b' b m a
fb' -> b -> (b' -> Proxy a' a b' b m (a, b)) -> Proxy a' a b' b m (a, b)
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 a -> b -> Proxy a' a b' b m (a, b)
go (b' -> Proxy a' a b' b m a
fb' b'
b') b
w)
M m (Proxy a' a b' b m a)
m -> m (Proxy a' a b' b m (a, b)) -> Proxy a' a b' b m (a, b)
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 a
p', b
w') <- m (Proxy a' a b' b m a) -> m (Proxy a' a b' b m a, b)
forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
listen m (Proxy a' a b' b m a)
m
Proxy a' a b' b m (a, b) -> m (Proxy a' a b' b m (a, b))
forall (m :: * -> *) a. Monad m => a -> m a
return (Proxy a' a b' b m a -> b -> Proxy a' a b' b m (a, b)
go Proxy a' a b' b m a
p' (b -> Proxy a' a b' b m (a, b)) -> b -> Proxy a' a b' b m (a, b)
forall a b. (a -> b) -> a -> b
$! b -> b -> b
forall a. Monoid a => a -> a -> a
mappend b
w b
w') )
Pure a
r -> (a, b) -> Proxy a' a b' b m (a, b)
forall a' a b' b (m :: * -> *) r. r -> Proxy a' a b' b m r
Pure (a
r, b
w)
pass :: Proxy a' a b' b m (a, w -> w) -> Proxy a' a b' b m a
pass Proxy a' a b' b m (a, w -> w)
p0 = Proxy a' a b' b m (a, w -> w) -> w -> Proxy a' a b' b m a
forall w (m :: * -> *) a' a b' b r.
MonadWriter w m =>
Proxy a' a b' b m (r, w -> w) -> w -> Proxy a' a b' b m r
go Proxy a' a b' b m (a, w -> w)
p0 w
forall a. Monoid a => a
mempty
where
go :: Proxy a' a b' b m (r, w -> w) -> w -> Proxy a' a b' b m r
go Proxy a' a b' b m (r, w -> w)
p w
w = case Proxy a' a b' b m (r, w -> w)
p of
Request a'
a' a -> Proxy a' a b' b m (r, w -> w)
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, w -> w) -> w -> Proxy a' a b' b m r
go (a -> Proxy a' a b' b m (r, w -> w)
fa a
a ) w
w)
Respond b
b b' -> Proxy a' a b' b m (r, w -> w)
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, w -> w) -> w -> Proxy a' a b' b m r
go (b' -> Proxy a' a b' b m (r, w -> w)
fb' b'
b') w
w)
M m (Proxy a' a b' b m (r, w -> w))
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, w -> w)
p', w
w') <- (w -> w)
-> m (Proxy a' a b' b m (r, w -> w), w)
-> m (Proxy a' a b' b m (r, w -> w), w)
forall w (m :: * -> *) a. MonadWriter w m => (w -> w) -> m a -> m a
censor (w -> w -> w
forall a b. a -> b -> a
const w
forall a. Monoid a => a
mempty) (m (Proxy a' a b' b m (r, w -> w))
-> m (Proxy a' a b' b m (r, w -> w), w)
forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
listen m (Proxy a' a b' b m (r, w -> w))
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, w -> w) -> w -> Proxy a' a b' b m r
go Proxy a' a b' b m (r, w -> w)
p' (w -> Proxy a' a b' b m r) -> w -> Proxy a' a b' b m r
forall a b. (a -> b) -> a -> b
$! w -> w -> w
forall a. Monoid a => a -> a -> a
mappend w
w w
w') )
Pure (r
r, w -> w
f) -> 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 (m (Proxy a' a b' b m r, w -> w) -> m (Proxy a' a b' b m r)
forall w (m :: * -> *) a. MonadWriter w m => m (a, w -> w) -> m a
pass ((Proxy a' a b' b m r, w -> w) -> m (Proxy a' a b' b m r, w -> w)
forall (m :: * -> *) a. Monad m => a -> m a
return (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, \w
_ -> w -> w
f w
w)))
instance MonadError e m => MonadError e (Proxy a' a b' b m) where
throwError :: e -> Proxy a' a b' b m a
throwError = m a -> Proxy a' a b' b m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> Proxy a' a b' b m a)
-> (e -> m a) -> e -> Proxy a' a b' b m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError
catchError :: Proxy a' a b' b m a
-> (e -> Proxy a' a b' b m a) -> Proxy a' a b' b m a
catchError Proxy a' a b' b m a
p0 e -> Proxy a' a b' b m a
f = Proxy a' a b' b m a -> Proxy a' a b' b m a
go Proxy a' a b' b m a
p0
where
go :: Proxy a' a b' b m a -> Proxy a' a b' b m a
go Proxy a' a b' b m a
p = case Proxy a' a b' b m a
p of
Request a'
a' a -> Proxy a' a b' b m a
fa -> a' -> (a -> Proxy a' a b' b m a) -> Proxy a' a b' b m a
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 a -> Proxy a' a b' b m a
go (a -> Proxy a' a b' b m a
fa a
a ))
Respond b
b b' -> Proxy a' a b' b m a
fb' -> b -> (b' -> Proxy a' a b' b m a) -> Proxy a' a b' b m a
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 a -> Proxy a' a b' b m a
go (b' -> Proxy a' a b' b m a
fb' b'
b'))
Pure a
r -> a -> Proxy a' a b' b m a
forall a' a b' b (m :: * -> *) r. r -> Proxy a' a b' b m r
Pure a
r
M m (Proxy a' a b' b m a)
m -> m (Proxy a' a b' b m a) -> Proxy a' a b' b m a
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 a
p' <- m (Proxy a' a b' b m a)
m
Proxy a' a b' b m a -> m (Proxy a' a b' b m a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Proxy a' a b' b m a -> Proxy a' a b' b m a
go Proxy a' a b' b m a
p') ) m (Proxy a' a b' b m a)
-> (e -> m (Proxy a' a b' b m a)) -> m (Proxy a' a b' b m a)
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` (\e
e -> Proxy a' a b' b m a -> m (Proxy a' a b' b m a)
forall (m :: * -> *) a. Monad m => a -> m a
return (e -> Proxy a' a b' b m a
f e
e)) )
instance MonadThrow m => MonadThrow (Proxy a' a b' b m) where
throwM :: e -> Proxy a' a b' b m a
throwM = m a -> Proxy a' a b' b m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> Proxy a' a b' b m a)
-> (e -> m a) -> e -> Proxy a' a b' b 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
throwM
{-# INLINE throwM #-}
instance MonadCatch m => MonadCatch (Proxy a' a b' b m) where
catch :: Proxy a' a b' b m a
-> (e -> Proxy a' a b' b m a) -> Proxy a' a b' b m a
catch Proxy a' a b' b m a
p0 e -> Proxy a' a b' b m a
f = Proxy a' a b' b m a -> Proxy a' a b' b m a
go Proxy a' a b' b m a
p0
where
go :: Proxy a' a b' b m a -> Proxy a' a b' b m a
go Proxy a' a b' b m a
p = case Proxy a' a b' b m a
p of
Request a'
a' a -> Proxy a' a b' b m a
fa -> a' -> (a -> Proxy a' a b' b m a) -> Proxy a' a b' b m a
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 a -> Proxy a' a b' b m a
go (a -> Proxy a' a b' b m a
fa a
a ))
Respond b
b b' -> Proxy a' a b' b m a
fb' -> b -> (b' -> Proxy a' a b' b m a) -> Proxy a' a b' b m a
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 a -> Proxy a' a b' b m a
go (b' -> Proxy a' a b' b m a
fb' b'
b'))
Pure a
r -> a -> Proxy a' a b' b m a
forall a' a b' b (m :: * -> *) r. r -> Proxy a' a b' b m r
Pure a
r
M m (Proxy a' a b' b m a)
m -> m (Proxy a' a b' b m a) -> Proxy a' a b' b m a
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 a
p' <- m (Proxy a' a b' b m a)
m
Proxy a' a b' b m a -> m (Proxy a' a b' b m a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Proxy a' a b' b m a -> Proxy a' a b' b m a
go Proxy a' a b' b m a
p') ) m (Proxy a' a b' b m a)
-> (e -> m (Proxy a' a b' b m a)) -> m (Proxy a' a b' b m a)
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
`Control.Monad.Catch.catch` (\e
e -> Proxy a' a b' b m a -> m (Proxy a' a b' b m a)
forall (m :: * -> *) a. Monad m => a -> m a
return (e -> Proxy a' a b' b m a
f e
e)) )
observe :: Monad m => Proxy a' a b' b m r -> Proxy a' a b' b m r
observe :: Proxy a' a b' b m r -> Proxy a' a b' b m r
observe Proxy a' a b' b m r
p0 = 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 (Proxy a' a b' b m r -> m (Proxy a' a b' b m r)
forall (m :: * -> *) a' a b' b r.
Monad m =>
Proxy a' a b' b m r -> m (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 -> m (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 -> Proxy a' a b' b m r -> m (Proxy a' a b' b m r)
forall (m :: * -> *) a. Monad m => a -> m a
return (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
forall (m :: * -> *) a' a b' b r.
Monad m =>
Proxy a' a b' b m r -> Proxy a' a b' b m r
observe (a -> Proxy a' a b' b m r
fa a
a )))
Respond b
b b' -> Proxy a' a b' b m r
fb' -> Proxy a' a b' b m r -> m (Proxy a' a b' b m r)
forall (m :: * -> *) a. Monad m => a -> m a
return (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
forall (m :: * -> *) a' a b' b r.
Monad m =>
Proxy a' a b' b m r -> Proxy a' a b' b m r
observe (b' -> Proxy a' a b' b m r
fb' b'
b')))
M m (Proxy a' a b' b m 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 -> m (Proxy a' a b' b m r))
-> m (Proxy a' a b' b m r)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Proxy a' a b' b m r -> m (Proxy a' a b' b m r)
go
Pure r
r -> Proxy a' a b' b m r -> m (Proxy a' a b' b m r)
forall (m :: * -> *) a. Monad m => a -> m a
return (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)
{-# INLINABLE observe #-}
type X = Void
closed :: X -> a
closed :: X -> a
closed = X -> a
forall a. X -> a
Data.Void.absurd
{-# INLINABLE closed #-}