{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
-- | Labelled effects, allowing flexible disambiguation and dependency of parametric effects.
--
-- Among other things, this can be used to:
--
-- * Improve inference by relating parametric effect types to some arbitrary label. This can be used to lift existing effect operations, or to define new ones; cf "Control.Effect.Reader.Labelled", "Control.Effect.State.Labelled" for examples of lifting effect operations into labelled effect operations.
--
-- * Express stronger relationships between an effect and the context it’s run in, e.g. to give an effect shadowing semantics, allowing only one instance of it to be active at a time in a given context.
--
-- * Resolve ambiguous types by relating parameters to a concrete label type.
--
-- @since 1.0.2.0
module Control.Effect.Labelled
( runLabelled
, Labelled(Labelled)
, LabelledMember(..)
, HasLabelled
, sendLabelled
, runUnderLabel
, UnderLabel(UnderLabel)
, module Control.Algebra
) where

import Control.Algebra
import Control.Applicative (Alternative)
import Control.Effect.Sum (reassociateSumL)
import Control.Monad (MonadPlus)
import Control.Monad.Fail as Fail
import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Data.Functor.Identity
import Data.Kind (Type)

-- | An effect transformer turning effects into labelled effects, and a carrier transformer turning carriers into labelled carriers for the same (labelled) effects.
--
-- @since 1.0.2.0
newtype Labelled (label :: k) (sub :: (Type -> Type) -> (Type -> Type)) m a = Labelled (sub m a)
  deriving
    ( Applicative (Labelled label sub m)
Labelled label sub m a
Applicative (Labelled label sub m)
-> (forall a. Labelled label sub m a)
-> (forall a.
    Labelled label sub m a
    -> Labelled label sub m a -> Labelled label sub m a)
-> (forall a. Labelled label sub m a -> Labelled label sub m [a])
-> (forall a. Labelled label sub m a -> Labelled label sub m [a])
-> Alternative (Labelled label sub m)
Labelled label sub m a
-> Labelled label sub m a -> Labelled label sub m a
Labelled label sub m a -> Labelled label sub m [a]
Labelled label sub m a -> Labelled label sub m [a]
forall a. Labelled label sub m a
forall a. Labelled label sub m a -> Labelled label sub m [a]
forall a.
Labelled label sub m a
-> Labelled label sub m a -> Labelled label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
Alternative (sub m) =>
Applicative (Labelled label sub m)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative (sub m) =>
Labelled label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative (sub m) =>
Labelled label sub m a -> Labelled label sub m [a]
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative (sub m) =>
Labelled label sub m a
-> Labelled label sub m a -> Labelled label sub 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 :: Labelled label sub m a -> Labelled label sub m [a]
$cmany :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative (sub m) =>
Labelled label sub m a -> Labelled label sub m [a]
some :: Labelled label sub m a -> Labelled label sub m [a]
$csome :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative (sub m) =>
Labelled label sub m a -> Labelled label sub m [a]
<|> :: Labelled label sub m a
-> Labelled label sub m a -> Labelled label sub m a
$c<|> :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative (sub m) =>
Labelled label sub m a
-> Labelled label sub m a -> Labelled label sub m a
empty :: Labelled label sub m a
$cempty :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative (sub m) =>
Labelled label sub m a
$cp1Alternative :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
Alternative (sub m) =>
Applicative (Labelled label sub m)
Alternative
    , Functor (Labelled label sub m)
a -> Labelled label sub m a
Functor (Labelled label sub m)
-> (forall a. a -> Labelled label sub m a)
-> (forall a b.
    Labelled label sub m (a -> b)
    -> Labelled label sub m a -> Labelled label sub m b)
-> (forall a b c.
    (a -> b -> c)
    -> Labelled label sub m a
    -> Labelled label sub m b
    -> Labelled label sub m c)
-> (forall a b.
    Labelled label sub m a
    -> Labelled label sub m b -> Labelled label sub m b)
-> (forall a b.
    Labelled label sub m a
    -> Labelled label sub m b -> Labelled label sub m a)
-> Applicative (Labelled label sub m)
Labelled label sub m a
-> Labelled label sub m b -> Labelled label sub m b
Labelled label sub m a
-> Labelled label sub m b -> Labelled label sub m a
Labelled label sub m (a -> b)
-> Labelled label sub m a -> Labelled label sub m b
(a -> b -> c)
-> Labelled label sub m a
-> Labelled label sub m b
-> Labelled label sub m c
forall a. a -> Labelled label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
Applicative (sub m) =>
Functor (Labelled label sub m)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Applicative (sub m) =>
a -> Labelled label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Applicative (sub m) =>
Labelled label sub m a
-> Labelled label sub m b -> Labelled label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Applicative (sub m) =>
Labelled label sub m a
-> Labelled label sub m b -> Labelled label sub m b
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Applicative (sub m) =>
Labelled label sub m (a -> b)
-> Labelled label sub m a -> Labelled label sub m b
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a b
       c.
Applicative (sub m) =>
(a -> b -> c)
-> Labelled label sub m a
-> Labelled label sub m b
-> Labelled label sub m c
forall a b.
Labelled label sub m a
-> Labelled label sub m b -> Labelled label sub m a
forall a b.
Labelled label sub m a
-> Labelled label sub m b -> Labelled label sub m b
forall a b.
Labelled label sub m (a -> b)
-> Labelled label sub m a -> Labelled label sub m b
forall a b c.
(a -> b -> c)
-> Labelled label sub m a
-> Labelled label sub m b
-> Labelled label sub 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
<* :: Labelled label sub m a
-> Labelled label sub m b -> Labelled label sub m a
$c<* :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Applicative (sub m) =>
Labelled label sub m a
-> Labelled label sub m b -> Labelled label sub m a
*> :: Labelled label sub m a
-> Labelled label sub m b -> Labelled label sub m b
$c*> :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Applicative (sub m) =>
Labelled label sub m a
-> Labelled label sub m b -> Labelled label sub m b
liftA2 :: (a -> b -> c)
-> Labelled label sub m a
-> Labelled label sub m b
-> Labelled label sub m c
$cliftA2 :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a b
       c.
Applicative (sub m) =>
(a -> b -> c)
-> Labelled label sub m a
-> Labelled label sub m b
-> Labelled label sub m c
<*> :: Labelled label sub m (a -> b)
-> Labelled label sub m a -> Labelled label sub m b
$c<*> :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Applicative (sub m) =>
Labelled label sub m (a -> b)
-> Labelled label sub m a -> Labelled label sub m b
pure :: a -> Labelled label sub m a
$cpure :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Applicative (sub m) =>
a -> Labelled label sub m a
$cp1Applicative :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
Applicative (sub m) =>
Functor (Labelled label sub m)
Applicative
    , a -> Labelled label sub m b -> Labelled label sub m a
(a -> b) -> Labelled label sub m a -> Labelled label sub m b
(forall a b.
 (a -> b) -> Labelled label sub m a -> Labelled label sub m b)
-> (forall a b.
    a -> Labelled label sub m b -> Labelled label sub m a)
-> Functor (Labelled label sub m)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Functor (sub m) =>
a -> Labelled label sub m b -> Labelled label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Functor (sub m) =>
(a -> b) -> Labelled label sub m a -> Labelled label sub m b
forall a b. a -> Labelled label sub m b -> Labelled label sub m a
forall a b.
(a -> b) -> Labelled label sub m a -> Labelled label sub m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Labelled label sub m b -> Labelled label sub m a
$c<$ :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Functor (sub m) =>
a -> Labelled label sub m b -> Labelled label sub m a
fmap :: (a -> b) -> Labelled label sub m a -> Labelled label sub m b
$cfmap :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Functor (sub m) =>
(a -> b) -> Labelled label sub m a -> Labelled label sub m b
Functor
    , Applicative (Labelled label sub m)
a -> Labelled label sub m a
Applicative (Labelled label sub m)
-> (forall a b.
    Labelled label sub m a
    -> (a -> Labelled label sub m b) -> Labelled label sub m b)
-> (forall a b.
    Labelled label sub m a
    -> Labelled label sub m b -> Labelled label sub m b)
-> (forall a. a -> Labelled label sub m a)
-> Monad (Labelled label sub m)
Labelled label sub m a
-> (a -> Labelled label sub m b) -> Labelled label sub m b
Labelled label sub m a
-> Labelled label sub m b -> Labelled label sub m b
forall a. a -> Labelled label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
Monad (sub m) =>
Applicative (Labelled label sub m)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Monad (sub m) =>
a -> Labelled label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Monad (sub m) =>
Labelled label sub m a
-> Labelled label sub m b -> Labelled label sub m b
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Monad (sub m) =>
Labelled label sub m a
-> (a -> Labelled label sub m b) -> Labelled label sub m b
forall a b.
Labelled label sub m a
-> Labelled label sub m b -> Labelled label sub m b
forall a b.
Labelled label sub m a
-> (a -> Labelled label sub m b) -> Labelled label sub 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 -> Labelled label sub m a
$creturn :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Monad (sub m) =>
a -> Labelled label sub m a
>> :: Labelled label sub m a
-> Labelled label sub m b -> Labelled label sub m b
$c>> :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Monad (sub m) =>
Labelled label sub m a
-> Labelled label sub m b -> Labelled label sub m b
>>= :: Labelled label sub m a
-> (a -> Labelled label sub m b) -> Labelled label sub m b
$c>>= :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Monad (sub m) =>
Labelled label sub m a
-> (a -> Labelled label sub m b) -> Labelled label sub m b
$cp1Monad :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
Monad (sub m) =>
Applicative (Labelled label sub m)
Monad
    , Monad (Labelled label sub m)
Monad (Labelled label sub m)
-> (forall a. String -> Labelled label sub m a)
-> MonadFail (Labelled label sub m)
String -> Labelled label sub m a
forall a. String -> Labelled label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
MonadFail (sub m) =>
Monad (Labelled label sub m)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadFail (sub m) =>
String -> Labelled label sub m a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
fail :: String -> Labelled label sub m a
$cfail :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadFail (sub m) =>
String -> Labelled label sub m a
$cp1MonadFail :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
MonadFail (sub m) =>
Monad (Labelled label sub m)
Fail.MonadFail
    , MonadFix -- ^ @since 1.1.1
    , Monad (Labelled label sub m)
Monad (Labelled label sub m)
-> (forall a. IO a -> Labelled label sub m a)
-> MonadIO (Labelled label sub m)
IO a -> Labelled label sub m a
forall a. IO a -> Labelled label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
MonadIO (sub m) =>
Monad (Labelled label sub m)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadIO (sub m) =>
IO a -> Labelled label sub m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> Labelled label sub m a
$cliftIO :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadIO (sub m) =>
IO a -> Labelled label sub m a
$cp1MonadIO :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
MonadIO (sub m) =>
Monad (Labelled label sub m)
MonadIO
    , Monad (Labelled label sub m)
Alternative (Labelled label sub m)
Labelled label sub m a
Alternative (Labelled label sub m)
-> Monad (Labelled label sub m)
-> (forall a. Labelled label sub m a)
-> (forall a.
    Labelled label sub m a
    -> Labelled label sub m a -> Labelled label sub m a)
-> MonadPlus (Labelled label sub m)
Labelled label sub m a
-> Labelled label sub m a -> Labelled label sub m a
forall a. Labelled label sub m a
forall a.
Labelled label sub m a
-> Labelled label sub m a -> Labelled label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
MonadPlus (sub m) =>
Monad (Labelled label sub m)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
MonadPlus (sub m) =>
Alternative (Labelled label sub m)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadPlus (sub m) =>
Labelled label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadPlus (sub m) =>
Labelled label sub m a
-> Labelled label sub m a -> Labelled label sub m a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
mplus :: Labelled label sub m a
-> Labelled label sub m a -> Labelled label sub m a
$cmplus :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadPlus (sub m) =>
Labelled label sub m a
-> Labelled label sub m a -> Labelled label sub m a
mzero :: Labelled label sub m a
$cmzero :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadPlus (sub m) =>
Labelled label sub m a
$cp2MonadPlus :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
MonadPlus (sub m) =>
Monad (Labelled label sub m)
$cp1MonadPlus :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
MonadPlus (sub m) =>
Alternative (Labelled label sub m)
MonadPlus
    , m a -> Labelled label sub m a
(forall (m :: * -> *) a. Monad m => m a -> Labelled label sub m a)
-> MonadTrans (Labelled label sub)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans sub, Monad m) =>
m a -> Labelled label sub m a
forall (m :: * -> *) a. Monad m => m a -> Labelled label sub m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: m a -> Labelled label sub m a
$clift :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans sub, Monad m) =>
m a -> Labelled label sub m a
MonadTrans
    )

-- | @since 1.0.2.0
runLabelled :: forall label sub m a . Labelled label sub m a -> sub m a
runLabelled :: Labelled label sub m a -> sub m a
runLabelled (Labelled sub m a
l) = sub m a
l
{-# INLINE runLabelled #-}

instance Algebra (eff :+: sig) (sub m) => Algebra (Labelled label eff :+: sig) (Labelled label sub m) where
  alg :: Handler ctx n (Labelled label sub m)
-> (:+:) (Labelled label eff) sig n a
-> ctx ()
-> Labelled label sub m (ctx a)
alg Handler ctx n (Labelled label sub m)
hdl = \case
    L Labelled label eff n a
eff -> sub m (ctx a) -> Labelled label sub m (ctx a)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
sub m a -> Labelled label sub m a
Labelled (sub m (ctx a) -> Labelled label sub m (ctx a))
-> (ctx () -> sub m (ctx a))
-> ctx ()
-> Labelled label sub m (ctx a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handler ctx n (sub m)
-> (:+:) eff sig n a -> ctx () -> sub m (ctx a)
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) (ctx :: * -> *)
       (n :: * -> *) a.
(Algebra sig m, Functor ctx) =>
Handler ctx n m -> sig n a -> ctx () -> m (ctx a)
alg (Labelled label sub m (ctx x) -> sub m (ctx x)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Labelled label sub m a -> sub m a
runLabelled (Labelled label sub m (ctx x) -> sub m (ctx x))
-> (ctx (n x) -> Labelled label sub m (ctx x))
-> ctx (n x)
-> sub m (ctx x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ctx (n x) -> Labelled label sub m (ctx x)
Handler ctx n (Labelled label sub m)
hdl) (eff n a -> (:+:) eff sig n a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
f m k -> (:+:) f g m k
L (Labelled label eff n a -> eff n a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Labelled label sub m a -> sub m a
runLabelled Labelled label eff n a
eff))
    R sig n a
sig -> sub m (ctx a) -> Labelled label sub m (ctx a)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
sub m a -> Labelled label sub m a
Labelled (sub m (ctx a) -> Labelled label sub m (ctx a))
-> (ctx () -> sub m (ctx a))
-> ctx ()
-> Labelled label sub m (ctx a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handler ctx n (sub m)
-> (:+:) eff sig n a -> ctx () -> sub m (ctx a)
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) (ctx :: * -> *)
       (n :: * -> *) a.
(Algebra sig m, Functor ctx) =>
Handler ctx n m -> sig n a -> ctx () -> m (ctx a)
alg (Labelled label sub m (ctx x) -> sub m (ctx x)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Labelled label sub m a -> sub m a
runLabelled (Labelled label sub m (ctx x) -> sub m (ctx x))
-> (ctx (n x) -> Labelled label sub m (ctx x))
-> ctx (n x)
-> sub m (ctx x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ctx (n x) -> Labelled label sub m (ctx x)
Handler ctx n (Labelled label sub m)
hdl) (sig n a -> (:+:) eff sig n a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
g m k -> (:+:) f g m k
R sig n a
sig)
  {-# INLINE alg #-}


-- | The class of labelled types present in a signature.
--
-- @since 1.0.2.0
class LabelledMember label (sub :: (Type -> Type) -> (Type -> Type)) sup | label sup -> sub where
  -- | Inject a member of a signature into the signature.
  --
  -- @since 1.0.2.0
  injLabelled :: Labelled label sub m a -> sup m a

-- | Reflexivity: @t@ is a member of itself.
instance LabelledMember label t (Labelled label t) where
  injLabelled :: Labelled label t m a -> Labelled label t m a
injLabelled = Labelled label t m a -> Labelled label t m a
forall a. a -> a
id
  {-# INLINE injLabelled #-}

-- | Left-recursion: if @t@ is a member of @l1 ':+:' l2 ':+:' r@, then we can inject it into @(l1 ':+:' l2) ':+:' r@ by injection into a right-recursive signature, followed by left-association.
instance {-# OVERLAPPABLE #-}
         LabelledMember label t (l1 :+: l2 :+: r)
      => LabelledMember label t ((l1 :+: l2) :+: r) where
  injLabelled :: Labelled label t m a -> (:+:) (l1 :+: l2) r m a
injLabelled = (:+:) l1 (l2 :+: r) m a -> (:+:) (l1 :+: l2) r m a
forall (l1 :: (* -> *) -> * -> *) (l2 :: (* -> *) -> * -> *)
       (r :: (* -> *) -> * -> *) (m :: * -> *) a.
(:+:) l1 (l2 :+: r) m a -> (:+:) (l1 :+: l2) r m a
reassociateSumL ((:+:) l1 (l2 :+: r) m a -> (:+:) (l1 :+: l2) r m a)
-> (Labelled label t m a -> (:+:) l1 (l2 :+: r) m a)
-> Labelled label t m a
-> (:+:) (l1 :+: l2) r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Labelled label t m a -> (:+:) l1 (l2 :+: r) m a
forall k (label :: k) (sub :: (* -> *) -> * -> *)
       (sup :: (* -> *) -> * -> *) (m :: * -> *) a.
LabelledMember label sub sup =>
Labelled label sub m a -> sup m a
injLabelled
  {-# INLINE injLabelled #-}

-- | Left-occurrence: if @t@ is at the head of a signature, we can inject it in O(1).
instance {-# OVERLAPPABLE #-}
         LabelledMember label l (Labelled label l :+: r) where
  injLabelled :: Labelled label l m a -> (:+:) (Labelled label l) r m a
injLabelled = Labelled label l m a -> (:+:) (Labelled label l) r m a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
f m k -> (:+:) f g m k
L
  {-# INLINE injLabelled #-}

-- | Right-recursion: if @t@ is a member of @r@, we can inject it into @r@ in O(n), followed by lifting that into @l ':+:' r@ in O(1).
instance {-# OVERLAPPABLE #-}
         LabelledMember label l r
      => LabelledMember label l (l' :+: r) where
  injLabelled :: Labelled label l m a -> (:+:) l' r m a
injLabelled = r m a -> (:+:) l' r m a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
g m k -> (:+:) f g m k
R (r m a -> (:+:) l' r m a)
-> (Labelled label l m a -> r m a)
-> Labelled label l m a
-> (:+:) l' r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Labelled label l m a -> r m a
forall k (label :: k) (sub :: (* -> *) -> * -> *)
       (sup :: (* -> *) -> * -> *) (m :: * -> *) a.
LabelledMember label sub sup =>
Labelled label sub m a -> sup m a
injLabelled
  {-# INLINE injLabelled #-}


-- | @m@ is a carrier for @sig@ containing @eff@ associated with @label@.
--
-- Note that if @eff@ is a sum, it will /not/ be decomposed into multiple 'LabelledMember' constraints. While this technically is possible, it results in unsolvable constraints, as the functional dependencies in 'Labelled' prevent assocating the same label with multiple distinct effects within a signature.
--
-- @since 1.0.2.0
type HasLabelled label eff sig m = (LabelledMember label eff sig, Algebra sig m)

-- | Construct a request for a labelled effect to be interpreted by some handler later on.
--
-- @since 1.0.2.0
sendLabelled :: forall label eff sig m a . HasLabelled label eff sig m => eff m a -> m a
sendLabelled :: eff m a -> m a
sendLabelled eff m a
op = Identity a -> a
forall a. Identity a -> a
runIdentity (Identity a -> a) -> m (Identity a) -> m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Handler Identity m m -> sig m a -> Identity () -> m (Identity a)
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) (ctx :: * -> *)
       (n :: * -> *) a.
(Algebra sig m, Functor ctx) =>
Handler ctx n m -> sig n a -> ctx () -> m (ctx a)
alg ((x -> Identity x) -> m x -> m (Identity x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap x -> Identity x
forall a. a -> Identity a
Identity (m x -> m (Identity x))
-> (Identity (m x) -> m x) -> Identity (m x) -> m (Identity x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identity (m x) -> m x
forall a. Identity a -> a
runIdentity) (Labelled label eff m a -> sig m a
forall k (label :: k) (sub :: (* -> *) -> * -> *)
       (sup :: (* -> *) -> * -> *) (m :: * -> *) a.
LabelledMember label sub sup =>
Labelled label sub m a -> sup m a
injLabelled @label (eff m a -> Labelled label eff m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
sub m a -> Labelled label sub m a
Labelled eff m a
op)) (() -> Identity ()
forall a. a -> Identity a
Identity ())
{-# INLINABLE sendLabelled #-}


-- | A transformer to lift effectful actions to labelled effectful actions.
--
-- @since 1.0.2.0
newtype UnderLabel (label :: k) (sub :: (Type -> Type) -> (Type -> Type)) (m :: Type -> Type) a = UnderLabel (m a)
  deriving
    ( Applicative (UnderLabel label sub m)
UnderLabel label sub m a
Applicative (UnderLabel label sub m)
-> (forall a. UnderLabel label sub m a)
-> (forall a.
    UnderLabel label sub m a
    -> UnderLabel label sub m a -> UnderLabel label sub m a)
-> (forall a.
    UnderLabel label sub m a -> UnderLabel label sub m [a])
-> (forall a.
    UnderLabel label sub m a -> UnderLabel label sub m [a])
-> Alternative (UnderLabel label sub m)
UnderLabel label sub m a
-> UnderLabel label sub m a -> UnderLabel label sub m a
UnderLabel label sub m a -> UnderLabel label sub m [a]
UnderLabel label sub m a -> UnderLabel label sub m [a]
forall a. UnderLabel label sub m a
forall a. UnderLabel label sub m a -> UnderLabel label sub m [a]
forall a.
UnderLabel label sub m a
-> UnderLabel label sub m a -> UnderLabel label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
Alternative m =>
Applicative (UnderLabel label sub m)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative m =>
UnderLabel label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative m =>
UnderLabel label sub m a -> UnderLabel label sub m [a]
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative m =>
UnderLabel label sub m a
-> UnderLabel label sub m a -> UnderLabel label sub 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 :: UnderLabel label sub m a -> UnderLabel label sub m [a]
$cmany :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative m =>
UnderLabel label sub m a -> UnderLabel label sub m [a]
some :: UnderLabel label sub m a -> UnderLabel label sub m [a]
$csome :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative m =>
UnderLabel label sub m a -> UnderLabel label sub m [a]
<|> :: UnderLabel label sub m a
-> UnderLabel label sub m a -> UnderLabel label sub m a
$c<|> :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative m =>
UnderLabel label sub m a
-> UnderLabel label sub m a -> UnderLabel label sub m a
empty :: UnderLabel label sub m a
$cempty :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative m =>
UnderLabel label sub m a
$cp1Alternative :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
Alternative m =>
Applicative (UnderLabel label sub m)
Alternative
    , Functor (UnderLabel label sub m)
a -> UnderLabel label sub m a
Functor (UnderLabel label sub m)
-> (forall a. a -> UnderLabel label sub m a)
-> (forall a b.
    UnderLabel label sub m (a -> b)
    -> UnderLabel label sub m a -> UnderLabel label sub m b)
-> (forall a b c.
    (a -> b -> c)
    -> UnderLabel label sub m a
    -> UnderLabel label sub m b
    -> UnderLabel label sub m c)
-> (forall a b.
    UnderLabel label sub m a
    -> UnderLabel label sub m b -> UnderLabel label sub m b)
-> (forall a b.
    UnderLabel label sub m a
    -> UnderLabel label sub m b -> UnderLabel label sub m a)
-> Applicative (UnderLabel label sub m)
UnderLabel label sub m a
-> UnderLabel label sub m b -> UnderLabel label sub m b
UnderLabel label sub m a
-> UnderLabel label sub m b -> UnderLabel label sub m a
UnderLabel label sub m (a -> b)
-> UnderLabel label sub m a -> UnderLabel label sub m b
(a -> b -> c)
-> UnderLabel label sub m a
-> UnderLabel label sub m b
-> UnderLabel label sub m c
forall a. a -> UnderLabel label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
Applicative m =>
Functor (UnderLabel label sub m)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Applicative m =>
a -> UnderLabel label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Applicative m =>
UnderLabel label sub m a
-> UnderLabel label sub m b -> UnderLabel label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Applicative m =>
UnderLabel label sub m a
-> UnderLabel label sub m b -> UnderLabel label sub m b
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Applicative m =>
UnderLabel label sub m (a -> b)
-> UnderLabel label sub m a -> UnderLabel label sub m b
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a b
       c.
Applicative m =>
(a -> b -> c)
-> UnderLabel label sub m a
-> UnderLabel label sub m b
-> UnderLabel label sub m c
forall a b.
UnderLabel label sub m a
-> UnderLabel label sub m b -> UnderLabel label sub m a
forall a b.
UnderLabel label sub m a
-> UnderLabel label sub m b -> UnderLabel label sub m b
forall a b.
UnderLabel label sub m (a -> b)
-> UnderLabel label sub m a -> UnderLabel label sub m b
forall a b c.
(a -> b -> c)
-> UnderLabel label sub m a
-> UnderLabel label sub m b
-> UnderLabel label sub 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
<* :: UnderLabel label sub m a
-> UnderLabel label sub m b -> UnderLabel label sub m a
$c<* :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Applicative m =>
UnderLabel label sub m a
-> UnderLabel label sub m b -> UnderLabel label sub m a
*> :: UnderLabel label sub m a
-> UnderLabel label sub m b -> UnderLabel label sub m b
$c*> :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Applicative m =>
UnderLabel label sub m a
-> UnderLabel label sub m b -> UnderLabel label sub m b
liftA2 :: (a -> b -> c)
-> UnderLabel label sub m a
-> UnderLabel label sub m b
-> UnderLabel label sub m c
$cliftA2 :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a b
       c.
Applicative m =>
(a -> b -> c)
-> UnderLabel label sub m a
-> UnderLabel label sub m b
-> UnderLabel label sub m c
<*> :: UnderLabel label sub m (a -> b)
-> UnderLabel label sub m a -> UnderLabel label sub m b
$c<*> :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Applicative m =>
UnderLabel label sub m (a -> b)
-> UnderLabel label sub m a -> UnderLabel label sub m b
pure :: a -> UnderLabel label sub m a
$cpure :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Applicative m =>
a -> UnderLabel label sub m a
$cp1Applicative :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
Applicative m =>
Functor (UnderLabel label sub m)
Applicative
    , a -> UnderLabel label sub m b -> UnderLabel label sub m a
(a -> b) -> UnderLabel label sub m a -> UnderLabel label sub m b
(forall a b.
 (a -> b) -> UnderLabel label sub m a -> UnderLabel label sub m b)
-> (forall a b.
    a -> UnderLabel label sub m b -> UnderLabel label sub m a)
-> Functor (UnderLabel label sub m)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Functor m =>
a -> UnderLabel label sub m b -> UnderLabel label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Functor m =>
(a -> b) -> UnderLabel label sub m a -> UnderLabel label sub m b
forall a b.
a -> UnderLabel label sub m b -> UnderLabel label sub m a
forall a b.
(a -> b) -> UnderLabel label sub m a -> UnderLabel label sub m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> UnderLabel label sub m b -> UnderLabel label sub m a
$c<$ :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Functor m =>
a -> UnderLabel label sub m b -> UnderLabel label sub m a
fmap :: (a -> b) -> UnderLabel label sub m a -> UnderLabel label sub m b
$cfmap :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Functor m =>
(a -> b) -> UnderLabel label sub m a -> UnderLabel label sub m b
Functor
    , Applicative (UnderLabel label sub m)
a -> UnderLabel label sub m a
Applicative (UnderLabel label sub m)
-> (forall a b.
    UnderLabel label sub m a
    -> (a -> UnderLabel label sub m b) -> UnderLabel label sub m b)
-> (forall a b.
    UnderLabel label sub m a
    -> UnderLabel label sub m b -> UnderLabel label sub m b)
-> (forall a. a -> UnderLabel label sub m a)
-> Monad (UnderLabel label sub m)
UnderLabel label sub m a
-> (a -> UnderLabel label sub m b) -> UnderLabel label sub m b
UnderLabel label sub m a
-> UnderLabel label sub m b -> UnderLabel label sub m b
forall a. a -> UnderLabel label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
Monad m =>
Applicative (UnderLabel label sub m)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Monad m =>
a -> UnderLabel label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Monad m =>
UnderLabel label sub m a
-> UnderLabel label sub m b -> UnderLabel label sub m b
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Monad m =>
UnderLabel label sub m a
-> (a -> UnderLabel label sub m b) -> UnderLabel label sub m b
forall a b.
UnderLabel label sub m a
-> UnderLabel label sub m b -> UnderLabel label sub m b
forall a b.
UnderLabel label sub m a
-> (a -> UnderLabel label sub m b) -> UnderLabel label sub 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 -> UnderLabel label sub m a
$creturn :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
Monad m =>
a -> UnderLabel label sub m a
>> :: UnderLabel label sub m a
-> UnderLabel label sub m b -> UnderLabel label sub m b
$c>> :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Monad m =>
UnderLabel label sub m a
-> UnderLabel label sub m b -> UnderLabel label sub m b
>>= :: UnderLabel label sub m a
-> (a -> UnderLabel label sub m b) -> UnderLabel label sub m b
$c>>= :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a
       b.
Monad m =>
UnderLabel label sub m a
-> (a -> UnderLabel label sub m b) -> UnderLabel label sub m b
$cp1Monad :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
Monad m =>
Applicative (UnderLabel label sub m)
Monad
    , Monad (UnderLabel label sub m)
Monad (UnderLabel label sub m)
-> (forall a. String -> UnderLabel label sub m a)
-> MonadFail (UnderLabel label sub m)
String -> UnderLabel label sub m a
forall a. String -> UnderLabel label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
MonadFail m =>
Monad (UnderLabel label sub m)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadFail m =>
String -> UnderLabel label sub m a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
fail :: String -> UnderLabel label sub m a
$cfail :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadFail m =>
String -> UnderLabel label sub m a
$cp1MonadFail :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
MonadFail m =>
Monad (UnderLabel label sub m)
Fail.MonadFail
    , MonadFix -- ^ @since 1.1.1
    , Monad (UnderLabel label sub m)
Monad (UnderLabel label sub m)
-> (forall a. IO a -> UnderLabel label sub m a)
-> MonadIO (UnderLabel label sub m)
IO a -> UnderLabel label sub m a
forall a. IO a -> UnderLabel label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
MonadIO m =>
Monad (UnderLabel label sub m)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadIO m =>
IO a -> UnderLabel label sub m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> UnderLabel label sub m a
$cliftIO :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadIO m =>
IO a -> UnderLabel label sub m a
$cp1MonadIO :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
MonadIO m =>
Monad (UnderLabel label sub m)
MonadIO
    , Monad (UnderLabel label sub m)
Alternative (UnderLabel label sub m)
UnderLabel label sub m a
Alternative (UnderLabel label sub m)
-> Monad (UnderLabel label sub m)
-> (forall a. UnderLabel label sub m a)
-> (forall a.
    UnderLabel label sub m a
    -> UnderLabel label sub m a -> UnderLabel label sub m a)
-> MonadPlus (UnderLabel label sub m)
UnderLabel label sub m a
-> UnderLabel label sub m a -> UnderLabel label sub m a
forall a. UnderLabel label sub m a
forall a.
UnderLabel label sub m a
-> UnderLabel label sub m a -> UnderLabel label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
MonadPlus m =>
Monad (UnderLabel label sub m)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
MonadPlus m =>
Alternative (UnderLabel label sub m)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadPlus m =>
UnderLabel label sub m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadPlus m =>
UnderLabel label sub m a
-> UnderLabel label sub m a -> UnderLabel label sub m a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
mplus :: UnderLabel label sub m a
-> UnderLabel label sub m a -> UnderLabel label sub m a
$cmplus :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadPlus m =>
UnderLabel label sub m a
-> UnderLabel label sub m a -> UnderLabel label sub m a
mzero :: UnderLabel label sub m a
$cmzero :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadPlus m =>
UnderLabel label sub m a
$cp2MonadPlus :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
MonadPlus m =>
Monad (UnderLabel label sub m)
$cp1MonadPlus :: forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *).
MonadPlus m =>
Alternative (UnderLabel label sub m)
MonadPlus
    )

-- | @since 1.0.2.0
runUnderLabel :: forall label sub m a . UnderLabel label sub m a -> m a
runUnderLabel :: UnderLabel label sub m a -> m a
runUnderLabel (UnderLabel m a
l) = m a
l
{-# INLINE runUnderLabel #-}

instance MonadTrans (UnderLabel sub label) where
  lift :: m a -> UnderLabel sub label m a
lift = m a -> UnderLabel sub label m a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
m a -> UnderLabel label sub m a
UnderLabel
  {-# INLINE lift #-}

instance (LabelledMember label sub sig, Algebra sig m) => Algebra (sub :+: sig) (UnderLabel label sub m) where
  alg :: Handler ctx n (UnderLabel label sub m)
-> (:+:) sub sig n a -> ctx () -> UnderLabel label sub m (ctx a)
alg Handler ctx n (UnderLabel label sub m)
hdl = \case
    L sub n a
sub -> m (ctx a) -> UnderLabel label sub m (ctx a)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
m a -> UnderLabel label sub m a
UnderLabel (m (ctx a) -> UnderLabel label sub m (ctx a))
-> (ctx () -> m (ctx a))
-> ctx ()
-> UnderLabel label sub m (ctx a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handler ctx n m -> sig n a -> ctx () -> m (ctx a)
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) (ctx :: * -> *)
       (n :: * -> *) a.
(Algebra sig m, Functor ctx) =>
Handler ctx n m -> sig n a -> ctx () -> m (ctx a)
alg (UnderLabel label sub m (ctx x) -> m (ctx x)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
UnderLabel label sub m a -> m a
runUnderLabel (UnderLabel label sub m (ctx x) -> m (ctx x))
-> (ctx (n x) -> UnderLabel label sub m (ctx x))
-> ctx (n x)
-> m (ctx x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ctx (n x) -> UnderLabel label sub m (ctx x)
Handler ctx n (UnderLabel label sub m)
hdl) (Labelled label sub n a -> sig n a
forall k (label :: k) (sub :: (* -> *) -> * -> *)
       (sup :: (* -> *) -> * -> *) (m :: * -> *) a.
LabelledMember label sub sup =>
Labelled label sub m a -> sup m a
injLabelled @label (sub n a -> Labelled label sub n a
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
sub m a -> Labelled label sub m a
Labelled sub n a
sub))
    R sig n a
sig -> m (ctx a) -> UnderLabel label sub m (ctx a)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
m a -> UnderLabel label sub m a
UnderLabel (m (ctx a) -> UnderLabel label sub m (ctx a))
-> (ctx () -> m (ctx a))
-> ctx ()
-> UnderLabel label sub m (ctx a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handler ctx n m -> sig n a -> ctx () -> m (ctx a)
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) (ctx :: * -> *)
       (n :: * -> *) a.
(Algebra sig m, Functor ctx) =>
Handler ctx n m -> sig n a -> ctx () -> m (ctx a)
alg (UnderLabel label sub m (ctx x) -> m (ctx x)
forall k (label :: k) (sub :: (* -> *) -> * -> *) (m :: * -> *) a.
UnderLabel label sub m a -> m a
runUnderLabel (UnderLabel label sub m (ctx x) -> m (ctx x))
-> (ctx (n x) -> UnderLabel label sub m (ctx x))
-> ctx (n x)
-> m (ctx x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ctx (n x) -> UnderLabel label sub m (ctx x)
Handler ctx n (UnderLabel label sub m)
hdl) sig n a
sig
  {-# INLINE alg #-}