{-# LANGUAGE DerivingVia #-}
{-# OPTIONS_HADDOCK not-home #-}
module Control.Effect.Internal.Regional where

import Control.Effect
import Control.Effect.Carrier

import Control.Effect.Type.Regional

import Control.Effect.Carrier.Internal.Interpret

import Control.Monad.Trans.Control
import Control.Monad.Trans.Identity

newtype HoistCall b = HoistCall (forall x. b x -> b x)

-- | A useful specialization of 'Regional' where the
-- constant type is @'HoistCall' b@. From this,
-- you can derive 'Control.Effect.Regional.hoist'.
type Hoist (b :: * -> *) = Regional (HoistCall b)

data HoistH

instance Carrier m => PrimHandler HoistH (Hoist m) m where
  effPrimHandler :: Hoist m m x -> m x
effPrimHandler (Regionally (HoistCall forall x. m x -> m x
b) m x
m) = m x -> m x
forall x. m x -> m x
b m x
m
  {-# INLINEABLE effPrimHandler #-}

data HoistToFinalH

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

deriving via InterpretPrimC HoistH (Hoist m) m
    instance Carrier m => Carrier (HoistC m)

instance ( Carrier m
         , MonadBaseControl b m
         )
      => PrimHandler HoistToFinalH (Hoist b) m where
  effPrimHandler :: Hoist b m x -> m x
effPrimHandler (Regionally (HoistCall forall x. b x -> b x
b) m x
m) = (RunInBase m b -> b (StM m x)) -> m x
forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(RunInBase m b -> b (StM m a)) -> m a
control ((RunInBase m b -> b (StM m x)) -> m x)
-> (RunInBase m b -> b (StM m x)) -> m x
forall a b. (a -> b) -> a -> b
$ \RunInBase m b
lower -> b (StM m x) -> b (StM m x)
forall x. b x -> b x
b (m x -> b (StM m x)
RunInBase m b
lower m x
m)
  {-# INLINEABLE effPrimHandler #-}