{-# OPTIONS_HADDOCK not-home #-}
module Control.Effect.Internal.Reader where

import Data.Coerce

import Control.Effect
import Control.Effect.Carrier

import Control.Effect.Type.ReaderPrim

import Control.Monad.Trans.Reader (ReaderT(..))
import qualified Control.Monad.Trans.Reader as R

-- | An effect for arbitrary input

data Ask i :: Effect where
  Ask :: Ask i m i

-- | An effect for locally modifying an environment

-- used to gain access to information.

data Local i :: Effect where
  Local :: (i -> i) -> m a -> Local i m a

-- | A pseudo-effect for connected @'Ask' i@ and @'Local' i@ effects.

--

-- @'Reader'@ should only ever be used inside of 'Eff' and 'Effs'

-- constraints. It is not a real effect! See 'Bundle'.

type Reader i = Bundle [Local i, Ask i]

newtype ReaderC i m a = ReaderC {
    ReaderC i m a -> ReaderT i m a
unReaderC :: ReaderT i m a
  }
  deriving ( a -> ReaderC i m b -> ReaderC i m a
(a -> b) -> ReaderC i m a -> ReaderC i m b
(forall a b. (a -> b) -> ReaderC i m a -> ReaderC i m b)
-> (forall a b. a -> ReaderC i m b -> ReaderC i m a)
-> Functor (ReaderC i m)
forall a b. a -> ReaderC i m b -> ReaderC i m a
forall a b. (a -> b) -> ReaderC i m a -> ReaderC i m b
forall i (m :: * -> *) a b.
Functor m =>
a -> ReaderC i m b -> ReaderC i m a
forall i (m :: * -> *) a b.
Functor m =>
(a -> b) -> ReaderC i m a -> ReaderC i m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> ReaderC i m b -> ReaderC i m a
$c<$ :: forall i (m :: * -> *) a b.
Functor m =>
a -> ReaderC i m b -> ReaderC i m a
fmap :: (a -> b) -> ReaderC i m a -> ReaderC i m b
$cfmap :: forall i (m :: * -> *) a b.
Functor m =>
(a -> b) -> ReaderC i m a -> ReaderC i m b
Functor, Functor (ReaderC i m)
a -> ReaderC i m a
Functor (ReaderC i m)
-> (forall a. a -> ReaderC i m a)
-> (forall a b.
    ReaderC i m (a -> b) -> ReaderC i m a -> ReaderC i m b)
-> (forall a b c.
    (a -> b -> c) -> ReaderC i m a -> ReaderC i m b -> ReaderC i m c)
-> (forall a b. ReaderC i m a -> ReaderC i m b -> ReaderC i m b)
-> (forall a b. ReaderC i m a -> ReaderC i m b -> ReaderC i m a)
-> Applicative (ReaderC i m)
ReaderC i m a -> ReaderC i m b -> ReaderC i m b
ReaderC i m a -> ReaderC i m b -> ReaderC i m a
ReaderC i m (a -> b) -> ReaderC i m a -> ReaderC i m b
(a -> b -> c) -> ReaderC i m a -> ReaderC i m b -> ReaderC i m c
forall a. a -> ReaderC i m a
forall a b. ReaderC i m a -> ReaderC i m b -> ReaderC i m a
forall a b. ReaderC i m a -> ReaderC i m b -> ReaderC i m b
forall a b. ReaderC i m (a -> b) -> ReaderC i m a -> ReaderC i m b
forall a b c.
(a -> b -> c) -> ReaderC i m a -> ReaderC i m b -> ReaderC i m c
forall i (m :: * -> *). Applicative m => Functor (ReaderC i m)
forall i (m :: * -> *) a. Applicative m => a -> ReaderC i m a
forall i (m :: * -> *) a b.
Applicative m =>
ReaderC i m a -> ReaderC i m b -> ReaderC i m a
forall i (m :: * -> *) a b.
Applicative m =>
ReaderC i m a -> ReaderC i m b -> ReaderC i m b
forall i (m :: * -> *) a b.
Applicative m =>
ReaderC i m (a -> b) -> ReaderC i m a -> ReaderC i m b
forall i (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> ReaderC i m a -> ReaderC i m b -> ReaderC i m c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: ReaderC i m a -> ReaderC i m b -> ReaderC i m a
$c<* :: forall i (m :: * -> *) a b.
Applicative m =>
ReaderC i m a -> ReaderC i m b -> ReaderC i m a
*> :: ReaderC i m a -> ReaderC i m b -> ReaderC i m b
$c*> :: forall i (m :: * -> *) a b.
Applicative m =>
ReaderC i m a -> ReaderC i m b -> ReaderC i m b
liftA2 :: (a -> b -> c) -> ReaderC i m a -> ReaderC i m b -> ReaderC i m c
$cliftA2 :: forall i (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> ReaderC i m a -> ReaderC i m b -> ReaderC i m c
<*> :: ReaderC i m (a -> b) -> ReaderC i m a -> ReaderC i m b
$c<*> :: forall i (m :: * -> *) a b.
Applicative m =>
ReaderC i m (a -> b) -> ReaderC i m a -> ReaderC i m b
pure :: a -> ReaderC i m a
$cpure :: forall i (m :: * -> *) a. Applicative m => a -> ReaderC i m a
$cp1Applicative :: forall i (m :: * -> *). Applicative m => Functor (ReaderC i m)
Applicative, Applicative (ReaderC i m)
a -> ReaderC i m a
Applicative (ReaderC i m)
-> (forall a b.
    ReaderC i m a -> (a -> ReaderC i m b) -> ReaderC i m b)
-> (forall a b. ReaderC i m a -> ReaderC i m b -> ReaderC i m b)
-> (forall a. a -> ReaderC i m a)
-> Monad (ReaderC i m)
ReaderC i m a -> (a -> ReaderC i m b) -> ReaderC i m b
ReaderC i m a -> ReaderC i m b -> ReaderC i m b
forall a. a -> ReaderC i m a
forall a b. ReaderC i m a -> ReaderC i m b -> ReaderC i m b
forall a b. ReaderC i m a -> (a -> ReaderC i m b) -> ReaderC i m b
forall i (m :: * -> *). Monad m => Applicative (ReaderC i m)
forall i (m :: * -> *) a. Monad m => a -> ReaderC i m a
forall i (m :: * -> *) a b.
Monad m =>
ReaderC i m a -> ReaderC i m b -> ReaderC i m b
forall i (m :: * -> *) a b.
Monad m =>
ReaderC i m a -> (a -> ReaderC i m b) -> ReaderC i m b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> ReaderC i m a
$creturn :: forall i (m :: * -> *) a. Monad m => a -> ReaderC i m a
>> :: ReaderC i m a -> ReaderC i m b -> ReaderC i m b
$c>> :: forall i (m :: * -> *) a b.
Monad m =>
ReaderC i m a -> ReaderC i m b -> ReaderC i m b
>>= :: ReaderC i m a -> (a -> ReaderC i m b) -> ReaderC i m b
$c>>= :: forall i (m :: * -> *) a b.
Monad m =>
ReaderC i m a -> (a -> ReaderC i m b) -> ReaderC i m b
$cp1Monad :: forall i (m :: * -> *). Monad m => Applicative (ReaderC i m)
Monad
           , Applicative (ReaderC i m)
ReaderC i m a
Applicative (ReaderC i m)
-> (forall a. ReaderC i m a)
-> (forall a. ReaderC i m a -> ReaderC i m a -> ReaderC i m a)
-> (forall a. ReaderC i m a -> ReaderC i m [a])
-> (forall a. ReaderC i m a -> ReaderC i m [a])
-> Alternative (ReaderC i m)
ReaderC i m a -> ReaderC i m a -> ReaderC i m a
ReaderC i m a -> ReaderC i m [a]
ReaderC i m a -> ReaderC i m [a]
forall a. ReaderC i m a
forall a. ReaderC i m a -> ReaderC i m [a]
forall a. ReaderC i m a -> ReaderC i m a -> ReaderC i m a
forall i (m :: * -> *). Alternative m => Applicative (ReaderC i m)
forall i (m :: * -> *) a. Alternative m => ReaderC i m a
forall i (m :: * -> *) a.
Alternative m =>
ReaderC i m a -> ReaderC i m [a]
forall i (m :: * -> *) a.
Alternative m =>
ReaderC i m a -> ReaderC i m a -> ReaderC i m a
forall (f :: * -> *).
Applicative f
-> (forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
many :: ReaderC i m a -> ReaderC i m [a]
$cmany :: forall i (m :: * -> *) a.
Alternative m =>
ReaderC i m a -> ReaderC i m [a]
some :: ReaderC i m a -> ReaderC i m [a]
$csome :: forall i (m :: * -> *) a.
Alternative m =>
ReaderC i m a -> ReaderC i m [a]
<|> :: ReaderC i m a -> ReaderC i m a -> ReaderC i m a
$c<|> :: forall i (m :: * -> *) a.
Alternative m =>
ReaderC i m a -> ReaderC i m a -> ReaderC i m a
empty :: ReaderC i m a
$cempty :: forall i (m :: * -> *) a. Alternative m => ReaderC i m a
$cp1Alternative :: forall i (m :: * -> *). Alternative m => Applicative (ReaderC i m)
Alternative, Monad (ReaderC i m)
Alternative (ReaderC i m)
ReaderC i m a
Alternative (ReaderC i m)
-> Monad (ReaderC i m)
-> (forall a. ReaderC i m a)
-> (forall a. ReaderC i m a -> ReaderC i m a -> ReaderC i m a)
-> MonadPlus (ReaderC i m)
ReaderC i m a -> ReaderC i m a -> ReaderC i m a
forall a. ReaderC i m a
forall a. ReaderC i m a -> ReaderC i m a -> ReaderC i m a
forall i (m :: * -> *). MonadPlus m => Monad (ReaderC i m)
forall i (m :: * -> *). MonadPlus m => Alternative (ReaderC i m)
forall i (m :: * -> *) a. MonadPlus m => ReaderC i m a
forall i (m :: * -> *) a.
MonadPlus m =>
ReaderC i m a -> ReaderC i m a -> ReaderC i m a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
mplus :: ReaderC i m a -> ReaderC i m a -> ReaderC i m a
$cmplus :: forall i (m :: * -> *) a.
MonadPlus m =>
ReaderC i m a -> ReaderC i m a -> ReaderC i m a
mzero :: ReaderC i m a
$cmzero :: forall i (m :: * -> *) a. MonadPlus m => ReaderC i m a
$cp2MonadPlus :: forall i (m :: * -> *). MonadPlus m => Monad (ReaderC i m)
$cp1MonadPlus :: forall i (m :: * -> *). MonadPlus m => Alternative (ReaderC i m)
MonadPlus
           , Monad (ReaderC i m)
Monad (ReaderC i m)
-> (forall a. (a -> ReaderC i m a) -> ReaderC i m a)
-> MonadFix (ReaderC i m)
(a -> ReaderC i m a) -> ReaderC i m a
forall a. (a -> ReaderC i m a) -> ReaderC i m a
forall i (m :: * -> *). MonadFix m => Monad (ReaderC i m)
forall i (m :: * -> *) a.
MonadFix m =>
(a -> ReaderC i m a) -> ReaderC i m a
forall (m :: * -> *).
Monad m -> (forall a. (a -> m a) -> m a) -> MonadFix m
mfix :: (a -> ReaderC i m a) -> ReaderC i m a
$cmfix :: forall i (m :: * -> *) a.
MonadFix m =>
(a -> ReaderC i m a) -> ReaderC i m a
$cp1MonadFix :: forall i (m :: * -> *). MonadFix m => Monad (ReaderC i m)
MonadFix, Monad (ReaderC i m)
Monad (ReaderC i m)
-> (forall a. String -> ReaderC i m a) -> MonadFail (ReaderC i m)
String -> ReaderC i m a
forall a. String -> ReaderC i m a
forall i (m :: * -> *). MonadFail m => Monad (ReaderC i m)
forall i (m :: * -> *) a. MonadFail m => String -> ReaderC i m a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
fail :: String -> ReaderC i m a
$cfail :: forall i (m :: * -> *) a. MonadFail m => String -> ReaderC i m a
$cp1MonadFail :: forall i (m :: * -> *). MonadFail m => Monad (ReaderC i m)
MonadFail, Monad (ReaderC i m)
Monad (ReaderC i m)
-> (forall a. IO a -> ReaderC i m a) -> MonadIO (ReaderC i m)
IO a -> ReaderC i m a
forall a. IO a -> ReaderC i m a
forall i (m :: * -> *). MonadIO m => Monad (ReaderC i m)
forall i (m :: * -> *) a. MonadIO m => IO a -> ReaderC i m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> ReaderC i m a
$cliftIO :: forall i (m :: * -> *) a. MonadIO m => IO a -> ReaderC i m a
$cp1MonadIO :: forall i (m :: * -> *). MonadIO m => Monad (ReaderC i m)
MonadIO
           , Monad (ReaderC i m)
e -> ReaderC i m a
Monad (ReaderC i m)
-> (forall e a. Exception e => e -> ReaderC i m a)
-> MonadThrow (ReaderC i m)
forall e a. Exception e => e -> ReaderC i m a
forall i (m :: * -> *). MonadThrow m => Monad (ReaderC i m)
forall i (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> ReaderC i m a
forall (m :: * -> *).
Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
throwM :: e -> ReaderC i m a
$cthrowM :: forall i (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> ReaderC i m a
$cp1MonadThrow :: forall i (m :: * -> *). MonadThrow m => Monad (ReaderC i m)
MonadThrow, MonadThrow (ReaderC i m)
MonadThrow (ReaderC i m)
-> (forall e a.
    Exception e =>
    ReaderC i m a -> (e -> ReaderC i m a) -> ReaderC i m a)
-> MonadCatch (ReaderC i m)
ReaderC i m a -> (e -> ReaderC i m a) -> ReaderC i m a
forall e a.
Exception e =>
ReaderC i m a -> (e -> ReaderC i m a) -> ReaderC i m a
forall i (m :: * -> *). MonadCatch m => MonadThrow (ReaderC i m)
forall i (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
ReaderC i m a -> (e -> ReaderC i m a) -> ReaderC i m a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
catch :: ReaderC i m a -> (e -> ReaderC i m a) -> ReaderC i m a
$ccatch :: forall i (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
ReaderC i m a -> (e -> ReaderC i m a) -> ReaderC i m a
$cp1MonadCatch :: forall i (m :: * -> *). MonadCatch m => MonadThrow (ReaderC i m)
MonadCatch, MonadCatch (ReaderC i m)
MonadCatch (ReaderC i m)
-> (forall b.
    ((forall a. ReaderC i m a -> ReaderC i m a) -> ReaderC i m b)
    -> ReaderC i m b)
-> (forall b.
    ((forall a. ReaderC i m a -> ReaderC i m a) -> ReaderC i m b)
    -> ReaderC i m b)
-> (forall a b c.
    ReaderC i m a
    -> (a -> ExitCase b -> ReaderC i m c)
    -> (a -> ReaderC i m b)
    -> ReaderC i m (b, c))
-> MonadMask (ReaderC i m)
ReaderC i m a
-> (a -> ExitCase b -> ReaderC i m c)
-> (a -> ReaderC i m b)
-> ReaderC i m (b, c)
((forall a. ReaderC i m a -> ReaderC i m a) -> ReaderC i m b)
-> ReaderC i m b
((forall a. ReaderC i m a -> ReaderC i m a) -> ReaderC i m b)
-> ReaderC i m b
forall b.
((forall a. ReaderC i m a -> ReaderC i m a) -> ReaderC i m b)
-> ReaderC i m b
forall a b c.
ReaderC i m a
-> (a -> ExitCase b -> ReaderC i m c)
-> (a -> ReaderC i m b)
-> ReaderC i m (b, c)
forall i (m :: * -> *). MonadMask m => MonadCatch (ReaderC i m)
forall i (m :: * -> *) b.
MonadMask m =>
((forall a. ReaderC i m a -> ReaderC i m a) -> ReaderC i m b)
-> ReaderC i m b
forall i (m :: * -> *) a b c.
MonadMask m =>
ReaderC i m a
-> (a -> ExitCase b -> ReaderC i m c)
-> (a -> ReaderC i m b)
-> ReaderC i m (b, c)
forall (m :: * -> *).
MonadCatch m
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall a b c.
    m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c))
-> MonadMask m
generalBracket :: ReaderC i m a
-> (a -> ExitCase b -> ReaderC i m c)
-> (a -> ReaderC i m b)
-> ReaderC i m (b, c)
$cgeneralBracket :: forall i (m :: * -> *) a b c.
MonadMask m =>
ReaderC i m a
-> (a -> ExitCase b -> ReaderC i m c)
-> (a -> ReaderC i m b)
-> ReaderC i m (b, c)
uninterruptibleMask :: ((forall a. ReaderC i m a -> ReaderC i m a) -> ReaderC i m b)
-> ReaderC i m b
$cuninterruptibleMask :: forall i (m :: * -> *) b.
MonadMask m =>
((forall a. ReaderC i m a -> ReaderC i m a) -> ReaderC i m b)
-> ReaderC i m b
mask :: ((forall a. ReaderC i m a -> ReaderC i m a) -> ReaderC i m b)
-> ReaderC i m b
$cmask :: forall i (m :: * -> *) b.
MonadMask m =>
((forall a. ReaderC i m a -> ReaderC i m a) -> ReaderC i m b)
-> ReaderC i m b
$cp1MonadMask :: forall i (m :: * -> *). MonadMask m => MonadCatch (ReaderC i m)
MonadMask
           , MonadBase b, MonadBaseControl b
           )
  deriving (m a -> ReaderC i m a
(forall (m :: * -> *) a. Monad m => m a -> ReaderC i m a)
-> MonadTrans (ReaderC i)
forall i (m :: * -> *) a. Monad m => m a -> ReaderC i m a
forall (m :: * -> *) a. Monad m => m a -> ReaderC i m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: m a -> ReaderC i m a
$clift :: forall i (m :: * -> *) a. Monad m => m a -> ReaderC i m a
MonadTrans, MonadTrans (ReaderC i)
m (StT (ReaderC i) a) -> ReaderC i m a
MonadTrans (ReaderC i)
-> (forall (m :: * -> *) a.
    Monad m =>
    (Run (ReaderC i) -> m a) -> ReaderC i m a)
-> (forall (m :: * -> *) a.
    Monad m =>
    m (StT (ReaderC i) a) -> ReaderC i m a)
-> MonadTransControl (ReaderC i)
(Run (ReaderC i) -> m a) -> ReaderC i m a
forall i. MonadTrans (ReaderC i)
forall i (m :: * -> *) a.
Monad m =>
m (StT (ReaderC i) a) -> ReaderC i m a
forall i (m :: * -> *) a.
Monad m =>
(Run (ReaderC i) -> m a) -> ReaderC i m a
forall (m :: * -> *) a.
Monad m =>
m (StT (ReaderC i) a) -> ReaderC i m a
forall (m :: * -> *) a.
Monad m =>
(Run (ReaderC i) -> m a) -> ReaderC i m a
forall (t :: (* -> *) -> * -> *).
MonadTrans t
-> (forall (m :: * -> *) a. Monad m => (Run t -> m a) -> t m a)
-> (forall (m :: * -> *) a. Monad m => m (StT t a) -> t m a)
-> MonadTransControl t
restoreT :: m (StT (ReaderC i) a) -> ReaderC i m a
$crestoreT :: forall i (m :: * -> *) a.
Monad m =>
m (StT (ReaderC i) a) -> ReaderC i m a
liftWith :: (Run (ReaderC i) -> m a) -> ReaderC i m a
$cliftWith :: forall i (m :: * -> *) a.
Monad m =>
(Run (ReaderC i) -> m a) -> ReaderC i m a
$cp1MonadTransControl :: forall i. MonadTrans (ReaderC i)
MonadTransControl)

instance ( Threads (ReaderT i) (Prims m)
         , Carrier m
         )
      => Carrier (ReaderC i m) where
  type Derivs (ReaderC i m) = Local i ': Ask i ': Derivs m
  type Prims  (ReaderC i m) = ReaderPrim i ': Prims m
  algPrims :: Algebra' (Prims (ReaderC i m)) (ReaderC i m) a
algPrims = Algebra' (Prims m) (ReaderC i m) a
-> (ReaderPrim i (ReaderC i m) a -> ReaderC i m a)
-> Algebra' (ReaderPrim i : Prims m) (ReaderC i m) a
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       (m :: * -> *) a.
RepresentationalEff e =>
Algebra' r m a -> (e m a -> m a) -> Algebra' (e : r) m a
powerAlg ((Union (Prims m) (ReaderT i m) a -> ReaderT i m a)
-> Algebra' (Prims m) (ReaderC i m) a
coerce (Algebra (Prims m) m -> Algebra (Prims m) (ReaderT i m)
forall (t :: (* -> *) -> * -> *) (p :: [(* -> *) -> * -> *])
       (m :: * -> *).
(Threads t p, Monad m) =>
Algebra p m -> Algebra p (t m)
thread @(ReaderT i) (Carrier m => Algebra (Prims m) m
forall (m :: * -> *) a. Carrier m => Algebra' (Prims m) m a
algPrims @m))) ((ReaderPrim i (ReaderC i m) a -> ReaderC i m a)
 -> Algebra' (ReaderPrim i : Prims m) (ReaderC i m) a)
-> (ReaderPrim i (ReaderC i m) a -> ReaderC i m a)
-> Algebra' (ReaderPrim i : Prims m) (ReaderC i m) a
forall a b. (a -> b) -> a -> b
$ \case
    ReaderPrim i (ReaderC i m) a
ReaderPrimAsk -> ReaderT a m a -> ReaderC a m a
forall i (m :: * -> *) a. ReaderT i m a -> ReaderC i m a
ReaderC ReaderT a m a
forall (m :: * -> *) r. Monad m => ReaderT r m r
R.ask
    ReaderPrimLocal i -> i
f (ReaderC ReaderT i m a
m) -> ReaderT i m a -> ReaderC i m a
forall i (m :: * -> *) a. ReaderT i m a -> ReaderC i m a
ReaderC ((i -> i) -> ReaderT i m a -> ReaderT i m a
forall r (m :: * -> *) a.
(r -> r) -> ReaderT r m a -> ReaderT r m a
R.local i -> i
f ReaderT i m a
m)
  {-# INLINEABLE algPrims #-}

  reformulate :: Reformulation'
  (Derivs (ReaderC i m)) (Prims (ReaderC i m)) (ReaderC i m) z a
reformulate forall x. ReaderC i m x -> z x
n Algebra (Prims (ReaderC i m)) z
alg =
    Algebra' (Ask i : Derivs m) z a
-> (Local i z a -> z a)
-> Algebra' (Local i : Ask i : Derivs m) z a
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       (m :: * -> *) a.
RepresentationalEff e =>
Algebra' r m a -> (e m a -> m a) -> Algebra' (e : r) m a
powerAlg (
    Algebra' (Derivs m) z a
-> (Ask i z a -> z a) -> Algebra' (Ask i : Derivs m) z a
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       (m :: * -> *) a.
RepresentationalEff e =>
Algebra' r m a -> (e m a -> m a) -> Algebra' (e : r) m a
powerAlg (
      Reformulation' (Derivs m) (Prims m) m z a
forall (m :: * -> *) (z :: * -> *) a.
(Carrier m, Monad z) =>
Reformulation' (Derivs m) (Prims m) m z a
reformulate (ReaderC i m x -> z x
forall x. ReaderC i m x -> z x
n (ReaderC i m x -> z x) -> (m x -> ReaderC i m x) -> m x -> z x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m x -> ReaderC i m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift) (Algebra' (ReaderPrim i : Prims m) z x -> Union (Prims m) z x -> z x
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       (m :: * -> *) a.
Algebra' (e : r) m a -> Algebra' r m a
weakenAlg Algebra' (ReaderPrim i : Prims m) z x
Algebra (Prims (ReaderC i m)) z
alg)
    ) ((Ask i z a -> z a) -> Algebra' (Ask i : Derivs m) z a)
-> (Ask i z a -> z a) -> Algebra' (Ask i : Derivs m) z a
forall a b. (a -> b) -> a -> b
$ \case
      Ask i z a
Ask -> ReaderC i m i -> z i
forall x. ReaderC i m x -> z x
n (ReaderT i m i -> ReaderC i m i
forall i (m :: * -> *) a. ReaderT i m a -> ReaderC i m a
ReaderC ReaderT i m i
forall (m :: * -> *) r. Monad m => ReaderT r m r
R.ask)
    ) ((Local i z a -> z a) -> Algebra' (Local i : Ask i : Derivs m) z a)
-> (Local i z a -> z a)
-> Algebra' (Local i : Ask i : Derivs m) z a
forall a b. (a -> b) -> a -> b
$ \case
      Local i -> i
f z a
m -> (Union (ReaderPrim i : Prims m) z a -> z a
Algebra (Prims (ReaderC i m)) z
alg (Union (ReaderPrim i : Prims m) z a -> z a)
-> (ReaderPrim i z a -> Union (ReaderPrim i : Prims m) z a)
-> ReaderPrim i z a
-> z a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReaderPrim i z a -> Union (ReaderPrim i : Prims m) z a
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       (m :: * -> *) a.
Member e r =>
e m a -> Union r m a
inj) (ReaderPrim i z a -> z a) -> ReaderPrim i z a -> z a
forall a b. (a -> b) -> a -> b
$ (i -> i) -> z a -> ReaderPrim i z a
forall i (m :: * -> *) a. (i -> i) -> m a -> ReaderPrim i m a
ReaderPrimLocal i -> i
f z a
m
  {-# INLINEABLE reformulate #-}