{-# LANGUAGE DerivingVia, MagicHash #-}
module Control.Effect.BaseControl
  ( -- * Effects
    BaseControl

    -- * Actions
  , withLowerToBase
  , gainBaseControl

   -- * Interpretations
  , runBaseControl
  , baseControlToFinal

    -- * MonadBaseControl
  , MonadBaseControl(..)
  , control

   -- * Threading utilities
  , threadBaseControlViaClass

    -- * Combinators for 'Algebra's
    -- Intended to be used for custom 'Carrier' instances when
    -- defining 'algPrims'.
  , powerAlgBaseControl
  , powerAlgBaseControlFinal

    -- * Carriers
  , GainBaseControlC(..)

  , BaseControlC
  , BaseControlToFinalC
  ) where

import Data.Coerce

import Control.Monad
import Control.Effect
import Control.Effect.Carrier

import Control.Effect.Type.Internal.BaseControl
import Control.Effect.Internal.BaseControl
import Control.Effect.Internal.Itself

import Control.Effect.Internal.Utils

import Control.Monad.Trans.Identity
import Control.Monad.Trans.Control
import GHC.Exts (Proxy#, proxy#)


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

instance (Monad m, MonadBase b z, Coercible z m)
      => MonadBase b (GainBaseControlC b z m) where
  liftBase :: b α -> GainBaseControlC b z m α
liftBase = z α -> GainBaseControlC b z m α
coerce (z α -> GainBaseControlC b z m α)
-> (b α -> z α) -> b α -> GainBaseControlC b z m α
forall c b a. Coercible c b => (b -> c) -> (a -> b) -> a -> c
#. forall α. MonadBase b z => b α -> z α
forall (b :: * -> *) (m :: * -> *) α. MonadBase b m => b α -> m α
liftBase @_ @z
  {-# INLINE liftBase #-}

instance (Monad m, MonadBaseControl b z, Coercible z m)
      => MonadBaseControl b (GainBaseControlC b z m) where
  type StM (GainBaseControlC b z m) a = StM z a

  liftBaseWith :: (RunInBase (GainBaseControlC b z m) b -> b a)
-> GainBaseControlC b z m a
liftBaseWith RunInBase (GainBaseControlC b z m) b -> b a
m = z a -> GainBaseControlC b z m a
coerce (z a -> GainBaseControlC b z m a)
-> z a -> GainBaseControlC b z m a
forall a b. (a -> b) -> a -> b
$ forall a. MonadBaseControl b z => (RunInBase z b -> b a) -> z a
forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(RunInBase m b -> b a) -> m a
liftBaseWith @_ @z ((RunInBase z b -> b a) -> z a) -> (RunInBase z b -> b a) -> z a
forall a b. (a -> b) -> a -> b
$ \RunInBase z b
lower -> RunInBase (GainBaseControlC b z m) b -> b a
m ((z a -> b (StM z a)) -> GainBaseControlC b z m a -> b (StM z a)
forall k1 k2 (m :: k1 -> *) (z :: k1 -> *) (n :: k2 -> *)
       (y :: k2 -> *) (a :: k1) (b :: k2).
(Coercible m z, Coercible n y) =>
(m a -> n b) -> z a -> y b
coerceTrans z a -> b (StM z a)
RunInBase z b
lower)
  {-# INLINE liftBaseWith #-}

  restoreM :: StM (GainBaseControlC b z m) a -> GainBaseControlC b z m a
restoreM =
    (StM z a -> z a) -> StM z a -> GainBaseControlC b z m a
coerce (StM z a -> z a
forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
StM m a -> m a
restoreM @_ @z @a) :: forall a. StM z a -> GainBaseControlC b z m a
  {-# INLINE restoreM #-}

newtype Stateful m a = Stateful { Stateful m a -> StM m a
getStateful :: StM m a }

-- | Gain access to a function that allows for lowering @m@ to the
-- base monad @b@.
--
-- This is less versatile, but easier to use than 'gainBaseControl'.
withLowerToBase :: forall b m a
                 . Eff (BaseControl b) m
                => (forall f. (forall x. m x -> b (f x)) -> b (f a))
                -> m a
withLowerToBase :: (forall (f :: * -> *). (forall x. m x -> b (f x)) -> b (f a))
-> m a
withLowerToBase forall (f :: * -> *). (forall x. m x -> b (f x)) -> b (f a)
main = m (m a) -> m a
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (m (m a) -> m a) -> m (m a) -> m a
forall a b. (a -> b) -> a -> b
$ BaseControl b m (m a) -> m (m a)
forall (e :: (* -> *) -> * -> *) (m :: * -> *) a.
(Member e (Derivs m), Carrier m) =>
e m a -> m a
send (BaseControl b m (m a) -> m (m a))
-> BaseControl b m (m a) -> m (m a)
forall a b. (a -> b) -> a -> b
$
  forall (m :: * -> *) a.
(forall (z :: * -> *).
 (MonadBaseControl b z, Coercible z m) =>
 Proxy# z -> a)
-> BaseControl b m a
forall (b :: * -> *) (m :: * -> *) a.
(forall (z :: * -> *).
 (MonadBaseControl b z, Coercible z m) =>
 Proxy# z -> a)
-> BaseControl b m a
GainBaseControl @b ((forall (z :: * -> *).
  (MonadBaseControl b z, Coercible z m) =>
  Proxy# z -> m a)
 -> BaseControl b m (m a))
-> (forall (z :: * -> *).
    (MonadBaseControl b z, Coercible z m) =>
    Proxy# z -> m a)
-> BaseControl b m (m a)
forall a b. (a -> b) -> a -> b
$ \(Proxy# z
_ :: Proxy# z) -> z a -> m a
forall k (m :: k -> *) (n :: k -> *) (a :: k).
Coercible m n =>
m a -> n a
coerceM (z a -> m a) -> z a -> m a
forall a b. (a -> b) -> a -> b
$ forall a.
MonadBaseControl b z =>
(RunInBase z b -> b (StM z a)) -> z a
forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(RunInBase m b -> b (StM m a)) -> m a
control @_ @z ((RunInBase z b -> b (StM z a)) -> z a)
-> (RunInBase z b -> b (StM z a)) -> z a
forall a b. (a -> b) -> a -> b
$ \RunInBase z b
lower ->
    Stateful z a -> StM z a
forall (m :: * -> *) a. Stateful m a -> StM m a
getStateful @z @a (Stateful z a -> StM z a) -> b (Stateful z a) -> b (StM z a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall x. m x -> b (Stateful z x)) -> b (Stateful z a)
forall (f :: * -> *). (forall x. m x -> b (f x)) -> b (f a)
main ((StM z x -> Stateful z x) -> b (StM z x) -> b (Stateful z x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. StM z a -> Stateful z a
forall (m :: * -> *) a. StM m a -> Stateful m a
Stateful @z) (b (StM z x) -> b (Stateful z x))
-> (m x -> b (StM z x)) -> m x -> b (Stateful z x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (z x -> b (StM z x)) -> m x -> b (StM z x)
forall k1 k2 (m :: k1 -> *) (z :: k1 -> *) (n :: k2 -> *)
       (y :: k2 -> *) (a :: k1) (b :: k2).
(Coercible m z, Coercible n y) =>
(m a -> n b) -> z a -> y b
coerceTrans z x -> b (StM z x)
RunInBase z b
lower)
{-# INLINE withLowerToBase #-}

-- | Locally gain access to a @'MonadBaseControl' b@ instance
-- within a region.
--
-- You'll need to use 'lift' if you want to use the 'MonadBaseControl' instance
-- with computations outside of the region.
-- This is common with effect handlers. For example:
--
-- @
-- import System.IO (FilePath, IOMode, Handle)
-- import qualified System.IO as SysIO
--
-- data WithFile m a where
--   WithFile :: FilePath -> IOMode -> (Handle -> m a) -> WithFile m a
--
-- runWithFile :: 'Eff' ('BaseControl' IO) m => 'SimpleInterpreterFor' WithFile m
-- runWithFile = 'interpretSimple' $ \case
--   WithFile fp mode c -> 'gainBaseControl' $ 'control' $ \lower ->
--     SysIO.withFile fp mode (\hdl -> lower (lift (c hdl)))
-- @
--
gainBaseControl
  :: forall b m a
   . Eff (BaseControl b) m
  => (  forall z
      . (MonadBaseControl b z, Coercible z m)
     => GainBaseControlC b z m a
     )
  -> m a
gainBaseControl :: (forall (z :: * -> *).
 (MonadBaseControl b z, Coercible z m) =>
 GainBaseControlC b z m a)
-> m a
gainBaseControl forall (z :: * -> *).
(MonadBaseControl b z, Coercible z m) =>
GainBaseControlC b z m a
main = m (m a) -> m a
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (m (m a) -> m a) -> m (m a) -> m a
forall a b. (a -> b) -> a -> b
$ BaseControl b m (m a) -> m (m a)
forall (e :: (* -> *) -> * -> *) (m :: * -> *) a.
(Member e (Derivs m), Carrier m) =>
e m a -> m a
send (BaseControl b m (m a) -> m (m a))
-> BaseControl b m (m a) -> m (m a)
forall a b. (a -> b) -> a -> b
$
  (forall (z :: * -> *).
 (MonadBaseControl b z, Coercible z m) =>
 Proxy# z -> m a)
-> BaseControl b m (m a)
forall (b :: * -> *) (m :: * -> *) a.
(forall (z :: * -> *).
 (MonadBaseControl b z, Coercible z m) =>
 Proxy# z -> a)
-> BaseControl b m a
GainBaseControl @b (\(Proxy# z
_ :: Proxy# z) -> GainBaseControlC b z m a -> m a
forall k (b :: k) k (z :: k) k (m :: k -> *) (a :: k).
GainBaseControlC b z m a -> m a
unGainBaseControlC ((MonadBaseControl b z, Coercible z m) => GainBaseControlC b z m a
forall (z :: * -> *).
(MonadBaseControl b z, Coercible z m) =>
GainBaseControlC b z m a
main @z))
{-# INLINE gainBaseControl #-}


-- | Run a @'BaseControl' m@ effect, where the base @m@ is the current monad.
--
-- @'Derivs' ('BaseControlC' m) = 'BaseControl' m ': 'Derivs' m@
--
-- @'Prims'  ('BaseControlC' m) = 'BaseControl' m ': 'Prims' m@
runBaseControl :: Carrier m => BaseControlC m a -> m a
runBaseControl :: BaseControlC m a -> m a
runBaseControl = BaseControlC m a -> m a
forall k (m :: k -> *) (a :: k). BaseControlC m a -> m a
unBaseControlC
{-# INLINE runBaseControl #-}

data BaseControlToFinalH
type BaseControlToFinalC b = InterpretPrimC BaseControlToFinalH (BaseControl b)

instance ( MonadBaseControl b m
         , Carrier m
         )
      => PrimHandler BaseControlToFinalH (BaseControl b) m where
  effPrimHandler :: BaseControl b m x -> m x
effPrimHandler (GainBaseControl forall (z :: * -> *).
(MonadBaseControl b z, Coercible z m) =>
Proxy# z -> x
main) = x -> m x
forall (m :: * -> *) a. Monad m => a -> m a
return (x -> m x) -> x -> m x
forall a b. (a -> b) -> a -> b
$ Proxy# m -> x
forall (z :: * -> *).
(MonadBaseControl b z, Coercible z m) =>
Proxy# z -> x
main (Proxy# m
forall k (a :: k). Proxy# a
proxy# :: Proxy# m)
  {-# INLINEABLE effPrimHandler #-}

-- | Run a @'BaseControl' b@ effect, where the base @b@ is the final base monad.
--
-- @'Derivs' ('BaseControlToFinalC' b m) = 'BaseControl' b ': 'Derivs' m@
--
-- @'Prims'  ('BaseControlToFinalC' b m) = 'BaseControl' b ': 'Prims' m@
baseControlToFinal :: (MonadBaseControl b m, Carrier m)
                   => BaseControlToFinalC b m a -> m a
baseControlToFinal :: BaseControlToFinalC b m a -> m a
baseControlToFinal = BaseControlToFinalC b m a -> m a
forall h (e :: (* -> *) -> * -> *) (m :: * -> *) a.
PrimHandler h e m =>
InterpretPrimC h e m a -> m a
interpretPrimViaHandler
{-# INLINE baseControlToFinal #-}


-- | Strengthen an @'Algebra' p m@ by adding a @'BaseControl' m@ handler
powerAlgBaseControl :: forall m p a
                     . Monad m
                    => Algebra' p m a
                    -> Algebra' (BaseControl m ': p) m a
powerAlgBaseControl :: Algebra' p m a -> Algebra' (BaseControl m : p) m a
powerAlgBaseControl Algebra' p m a
alg = Algebra' p m a
-> (BaseControl m m a -> m a) -> Algebra' (BaseControl m : p) m a
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       (m :: * -> *) a.
RepresentationalEff e =>
Algebra' r m a -> (e m a -> m a) -> Algebra' (e : r) m a
powerAlg Algebra' p m a
alg ((BaseControl m m a -> m a) -> Algebra' (BaseControl m : p) m a)
-> (BaseControl m m a -> m a) -> Algebra' (BaseControl m : p) m a
forall a b. (a -> b) -> a -> b
$ \case
  GainBaseControl forall (z :: * -> *).
(MonadBaseControl m z, Coercible z m) =>
Proxy# z -> a
main -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> m a) -> a -> m a
forall a b. (a -> b) -> a -> b
$ Proxy# (Itself m) -> a
forall (z :: * -> *).
(MonadBaseControl m z, Coercible z m) =>
Proxy# z -> a
main (Proxy# (Itself m)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (Itself m))
{-# INLINEABLE powerAlgBaseControl #-}

-- | Strengthen an @'Algebra' p m@ by adding a @'BaseControl' b@ handler,
-- where @b@ is the final base monad.
powerAlgBaseControlFinal :: forall b m p a
                          . MonadBaseControl b m
                         => Algebra' p m a
                         -> Algebra' (BaseControl b ': p) m a
powerAlgBaseControlFinal :: Algebra' p m a -> Algebra' (BaseControl b : p) m a
powerAlgBaseControlFinal Algebra' p m a
alg = Algebra' p m a
-> (BaseControl b m a -> m a) -> Algebra' (BaseControl b : p) m a
forall (e :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       (m :: * -> *) a.
RepresentationalEff e =>
Algebra' r m a -> (e m a -> m a) -> Algebra' (e : r) m a
powerAlg Algebra' p m a
alg ((BaseControl b m a -> m a) -> Algebra' (BaseControl b : p) m a)
-> (BaseControl b m a -> m a) -> Algebra' (BaseControl b : p) m a
forall a b. (a -> b) -> a -> b
$ \case
  GainBaseControl forall (z :: * -> *).
(MonadBaseControl b z, Coercible z m) =>
Proxy# z -> a
main -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> m a) -> a -> m a
forall a b. (a -> b) -> a -> b
$ Proxy# m -> a
forall (z :: * -> *).
(MonadBaseControl b z, Coercible z m) =>
Proxy# z -> a
main (Proxy# m
forall k (a :: k). Proxy# a
proxy# :: Proxy# m)
{-# INLINEABLE powerAlgBaseControlFinal #-}