{-# LANGUAGE DerivingVia #-}
module Control.Effect.Union
  ( -- * Effects
    Union(..)
  , ElemOf(..)

    -- * Actions
  , unionize

  , unionizeHead

    -- * Interpretations
  , runUnion

    -- * Utilities
  , inj
  , decomp
  , extract
  , weaken
  , absurdU
  , absurdMember
  , membership

    -- * Carriers
  , UnionizeC
  , UnionizeHeadC
  , UnionC
  ) where

import Data.Coerce

import Control.Effect

import Control.Effect.Internal
import Control.Effect.Internal.Utils
import Control.Effect.Internal.Union
import Control.Effect.Internal.Derive
import Control.Effect.Internal.Membership
import Control.Effect.Internal.KnownList

-- For coercion purposes
import Control.Monad.Trans.Identity
import Control.Effect.Carrier.Internal.Compose
import Control.Effect.Carrier.Internal.Intro


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

instance ( KnownList l
         , HeadEffs l m
         )
      => Carrier (UnionC l m) where
  type Derivs (UnionC l m) = Union l ': StripPrefix l (Derivs m)
  type Prims  (UnionC l m) = Prims m

  algPrims :: Algebra' (Prims (UnionC l m)) (UnionC l m) a
algPrims = (Union (Prims m) m a -> m a) -> Algebra' (Prims m) (UnionC l m) a
coerce (forall a. Carrier m => Algebra' (Prims m) m a
forall (m :: * -> *) a. Carrier m => Algebra' (Prims m) m a
algPrims @m)
  {-# INLINEABLE algPrims #-}

  reformulate :: Reformulation'
  (Derivs (UnionC l m)) (Prims (UnionC l m)) (UnionC l m) z a
reformulate (n :: forall x. UnionC l m x -> z x) Algebra (Prims (UnionC l m)) z
alg =
    let
      algDerivs' :: Algebra (Derivs m) z
      algDerivs' :: Union (Derivs m) z x -> z x
algDerivs' = Reformulation' (Derivs m) (Prims m) m z x
forall (m :: * -> *) (z :: * -> *) a.
(Carrier m, Monad z) =>
Reformulation' (Derivs m) (Prims m) m z a
reformulate @m (UnionC l m x -> z x
forall x. UnionC l m x -> z x
n (UnionC l m x -> z x) -> (m x -> UnionC l m x) -> m x -> z x
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# m x -> UnionC l m x
forall k (l :: [Effect]) (m :: k -> *) (a :: k).
m a -> UnionC l m a
UnionC) forall x. Union (Prims m) z x -> z x
Algebra (Prims (UnionC l m)) z
alg
    in
      Algebra' (StripPrefix l (Derivs m)) z a
-> (Union l z a -> z a)
-> Algebra' (Union l : StripPrefix l (Derivs m)) z a
forall (e :: Effect) (r :: [Effect]) (m :: * -> *) a.
RepresentationalEff e =>
Algebra' r m a -> (e m a -> m a) -> Algebra' (e : r) m a
powerAlg (SList l
-> Algebra (Append l (StripPrefix l (Derivs m))) z
-> Algebra (StripPrefix l (Derivs m)) z
forall (l :: [Effect]) (r :: [Effect]) (m :: * -> *).
SList l -> Algebra (Append l r) m -> Algebra r m
weakenAlgN (KnownList l => SList l
forall a (l :: [a]). KnownList l => SList l
singList @l) Algebra (Append l (StripPrefix l (Derivs m))) z
Algebra (Derivs m) z
algDerivs') ((Union l z a -> z a)
 -> Algebra' (Union l : StripPrefix l (Derivs m)) z a)
-> (Union l z a -> z a)
-> Algebra' (Union l : StripPrefix l (Derivs m)) z a
forall a b. (a -> b) -> a -> b
$ \(Union ElemOf e l
pr e z a
e) ->
        Union (Derivs m) z a -> z a
Algebra (Derivs m) z
algDerivs' (ElemOf e (Derivs m) -> e z a -> Union (Derivs m) z a
forall (z :: * -> *) (m :: * -> *) (e :: Effect) (r :: [Effect]) a.
Coercible z m =>
ElemOf e r -> e z a -> Union r m a
Union (ElemOf e l -> ElemOf e (Append l (StripPrefix l (Derivs m)))
forall a (r :: [a]) (e :: a) (l :: [a]).
ElemOf e l -> ElemOf e (Append l r)
lengthenMembership @(StripPrefix l (Derivs m)) ElemOf e l
pr) e z a
e)
  {-# INLINEABLE reformulate #-}

  algDerivs :: Algebra' (Derivs (UnionC l m)) (UnionC l m) a
algDerivs =
    let
      algD' :: Algebra (Derivs m) (UnionC l m)
      algD' :: Union (Derivs m) (UnionC l m) x -> UnionC l m x
algD' = (Union (Derivs m) m x -> m x)
-> Union (Derivs m) (UnionC l m) x -> UnionC l m x
coerce (forall a. Carrier m => Algebra' (Derivs m) m a
forall (m :: * -> *) a. Carrier m => Algebra' (Derivs m) m a
algDerivs @m)
    in
      Algebra' (StripPrefix l (Derivs m)) (UnionC l m) a
-> (Union l (UnionC l m) a -> UnionC l m a)
-> Algebra' (Union l : StripPrefix l (Derivs m)) (UnionC l m) a
forall (e :: Effect) (r :: [Effect]) (m :: * -> *) a.
RepresentationalEff e =>
Algebra' r m a -> (e m a -> m a) -> Algebra' (e : r) m a
powerAlg (SList l
-> Algebra (Append l (StripPrefix l (Derivs m))) (UnionC l m)
-> Algebra (StripPrefix l (Derivs m)) (UnionC l m)
forall (l :: [Effect]) (r :: [Effect]) (m :: * -> *).
SList l -> Algebra (Append l r) m -> Algebra r m
weakenAlgN (KnownList l => SList l
forall a (l :: [a]). KnownList l => SList l
singList @l) Algebra (Append l (StripPrefix l (Derivs m))) (UnionC l m)
Algebra (Derivs m) (UnionC l m)
algD') ((Union l (UnionC l m) a -> UnionC l m a)
 -> Algebra' (Union l : StripPrefix l (Derivs m)) (UnionC l m) a)
-> (Union l (UnionC l m) a -> UnionC l m a)
-> Algebra' (Union l : StripPrefix l (Derivs m)) (UnionC l m) a
forall a b. (a -> b) -> a -> b
$ \(Union ElemOf e l
pr e z a
e) ->
        Union (Derivs m) (UnionC l m) a -> UnionC l m a
Algebra (Derivs m) (UnionC l m)
algD' (ElemOf e (Derivs m) -> e z a -> Union (Derivs m) (UnionC l m) a
forall (z :: * -> *) (m :: * -> *) (e :: Effect) (r :: [Effect]) a.
Coercible z m =>
ElemOf e r -> e z a -> Union r m a
Union (ElemOf e l -> ElemOf e (Append l (StripPrefix l (Derivs m)))
forall a (r :: [a]) (e :: a) (l :: [a]).
ElemOf e l -> ElemOf e (Append l r)
lengthenMembership @(StripPrefix l (Derivs m)) ElemOf e l
pr) e z a
e)
  {-# INLINEABLE algDerivs #-}

-- | Run an @'Union' b@ effect by placing the effects of @b@ on top of the
-- effect stack.
--
-- @'Derivs' ('UnionC' b m) = Union b ': 'StripPrefix' b ('Derivs' m)@
--
-- @'Prims'  ('UnionC' b m) = 'Prims' m@
runUnion :: forall b m a
          . ( HeadEffs b m
            , KnownList b
            )
         => UnionC b m a
         -> m a
runUnion :: UnionC b m a -> m a
runUnion = UnionC b m a -> m a
forall (l :: [Effect]) k (m :: k -> *) (a :: k).
UnionC l m a -> m a
unUnionC
{-# INLINE runUnion #-}

-- | Sends uses of effects in @b@ to a @'Union' b@ effect.
--
-- @'Derivs' (UnionizeC b m) = b ++ 'Derivs' m@
unionize :: ( Eff (Union b) m
            , KnownList b
            )
         => UnionizeC b m a
         -> m a
unionize :: UnionizeC b m a -> m a
unionize = UnionizeC b m a -> m a
forall k (b :: k) k (m :: k -> *) (a :: k). UnionizeC b m a -> m a
unUnionizeC
{-# INLINE unionize #-}

type UnionizeHeadC b = CompositionC
 '[ IntroC b '[Union b]
  , UnionizeC b
  ]


-- | Rewrite uses of effects in @b@ into a @'Union' b@ effect on top of the effect stack.
--
-- @'Derivs' (UnionizeC b m) = b ++ StripPrefix '['Union' b] 'Derivs' m@
unionizeHead :: ( HeadEff (Union b) m
                , KnownList b
                )
             => UnionizeHeadC b m a
             -> m a
unionizeHead :: UnionizeHeadC b m a -> m a
unionizeHead = UnionizeHeadC b m a -> m a
coerce
{-# INLINE unionizeHead #-}


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

instance ( KnownList b
         , Eff (Union b) m
         )
      => Carrier (UnionizeC b m) where
  type Derivs (UnionizeC b m) = Append b (Derivs m)
  type Prims  (UnionizeC b m) = Prims m

  algPrims :: Algebra' (Prims (UnionizeC b m)) (UnionizeC b m) a
algPrims = (Union (Prims m) m a -> m a)
-> Algebra' (Prims m) (UnionizeC b m) a
coerce (forall a. Carrier m => Algebra' (Prims m) m a
forall (m :: * -> *) a. Carrier m => Algebra' (Prims m) m a
algPrims @m)
  {-# INLINE algPrims #-}

  reformulate :: Reformulation'
  (Derivs (UnionizeC b m))
  (Prims (UnionizeC b m))
  (UnionizeC b m)
  z
  a
reformulate forall x. UnionizeC b m x -> z x
n Algebra (Prims (UnionizeC b m)) z
alg (Union ElemOf e (Derivs (UnionizeC b m))
pr e z a
e) =
    case SList b
-> ElemOf e (Append b (Derivs m))
-> Either (ElemOf e b) (ElemOf e (Derivs m))
forall a (r :: [a]) (e :: a) (l :: [a]).
SList l
-> ElemOf e (Append l r) -> Either (ElemOf e l) (ElemOf e r)
splitMembership @(Derivs m) (KnownList b => SList b
forall a (l :: [a]). KnownList l => SList l
singList @b) ElemOf e (Append b (Derivs m))
ElemOf e (Derivs (UnionizeC b m))
pr of
      Left ElemOf e b
pr'  -> 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 (UnionizeC b m x -> z x
forall x. UnionizeC b m x -> z x
n (UnionizeC b m x -> z x) -> (m x -> UnionizeC b m x) -> m x -> z x
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# m x -> UnionizeC b m x
forall k k (b :: k) (m :: k -> *) (a :: k). m a -> UnionizeC b m a
UnionizeC) forall x. Union (Prims m) z x -> z x
Algebra (Prims (UnionizeC b m)) z
alg (Union (Derivs m) z a -> z a) -> Union (Derivs m) z a -> z a
forall a b. (a -> b) -> a -> b
$ Union b z a -> Union (Derivs m) z a
forall (e :: Effect) (r :: [Effect]) (m :: * -> *) a.
Member e r =>
e m a -> Union r m a
inj (ElemOf e b -> e z a -> Union b z a
forall (z :: * -> *) (m :: * -> *) (e :: Effect) (r :: [Effect]) a.
Coercible z m =>
ElemOf e r -> e z a -> Union r m a
Union ElemOf e b
pr' e z a
e)
      Right ElemOf e (Derivs m)
pr' -> 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 (UnionizeC b m x -> z x
forall x. UnionizeC b m x -> z x
n (UnionizeC b m x -> z x) -> (m x -> UnionizeC b m x) -> m x -> z x
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# m x -> UnionizeC b m x
forall k k (b :: k) (m :: k -> *) (a :: k). m a -> UnionizeC b m a
UnionizeC) forall x. Union (Prims m) z x -> z x
Algebra (Prims (UnionizeC b m)) z
alg (ElemOf e (Derivs m) -> e z a -> Union (Derivs m) z a
forall (z :: * -> *) (m :: * -> *) (e :: Effect) (r :: [Effect]) a.
Coercible z m =>
ElemOf e r -> e z a -> Union r m a
Union ElemOf e (Derivs m)
pr' e z a
e)
  {-# INLINE reformulate #-}

  algDerivs :: Algebra' (Derivs (UnionizeC b m)) (UnionizeC b m) a
algDerivs (Union ElemOf e (Derivs (UnionizeC b m))
pr e z a
e) =
    case SList b
-> ElemOf e (Append b (Derivs m))
-> Either (ElemOf e b) (ElemOf e (Derivs m))
forall a (r :: [a]) (e :: a) (l :: [a]).
SList l
-> ElemOf e (Append l r) -> Either (ElemOf e l) (ElemOf e r)
splitMembership @(Derivs m) (KnownList b => SList b
forall a (l :: [a]). KnownList l => SList l
singList @b) ElemOf e (Append b (Derivs m))
ElemOf e (Derivs (UnionizeC b m))
pr of
      Left ElemOf e b
pr'  -> m a -> UnionizeC b m a
forall k k (b :: k) (m :: k -> *) (a :: k). m a -> UnionizeC b m a
UnionizeC (m a -> UnionizeC b m a) -> m a -> UnionizeC b m a
forall a b. (a -> b) -> a -> b
$ forall a. Carrier m => Algebra' (Derivs m) m a
forall (m :: * -> *) a. Carrier m => Algebra' (Derivs m) m a
algDerivs @m Algebra' (Derivs m) m a -> Algebra' (Derivs m) m a
forall a b. (a -> b) -> a -> b
$ Union b m a -> Union (Derivs m) m a
forall (e :: Effect) (r :: [Effect]) (m :: * -> *) a.
Member e r =>
e m a -> Union r m a
inj (ElemOf e b -> e z a -> Union b m a
forall (z :: * -> *) (m :: * -> *) (e :: Effect) (r :: [Effect]) a.
Coercible z m =>
ElemOf e r -> e z a -> Union r m a
Union ElemOf e b
pr' e z a
e)
      Right ElemOf e (Derivs m)
pr' -> m a -> UnionizeC b m a
forall k k (b :: k) (m :: k -> *) (a :: k). m a -> UnionizeC b m a
UnionizeC (m a -> UnionizeC b m a) -> m a -> UnionizeC b m a
forall a b. (a -> b) -> a -> b
$ Algebra' (Derivs m) m a
forall (m :: * -> *) a. Carrier m => Algebra' (Derivs m) m a
algDerivs @m (ElemOf e (Derivs m) -> e z a -> Union (Derivs m) m a
forall (z :: * -> *) (m :: * -> *) (e :: Effect) (r :: [Effect]) a.
Coercible z m =>
ElemOf e r -> e z a -> Union r m a
Union ElemOf e (Derivs m)
pr' e z a
e)
  {-# INLINE algDerivs #-}