fused-effects-1.1.1.0: A fast, flexible, fused effect system.
Safe HaskellNone
LanguageHaskell2010

Control.Effect.Labelled

Description

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

Synopsis

Documentation

runLabelled :: forall label sub m a. Labelled label sub m a -> sub m a Source #

Since: 1.0.2.0

newtype Labelled (label :: k) (sub :: (Type -> Type) -> Type -> Type) m a Source #

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

Constructors

Labelled (sub m a) 

Instances

Instances details
LabelledMember (label :: k) l (Labelled label l :+: r) Source #

Left-occurrence: if t is at the head of a signature, we can inject it in O(1).

Instance details

Defined in Control.Effect.Labelled

Methods

injLabelled :: forall (m :: Type -> Type) a. Labelled label l m a -> (Labelled label l :+: r) m a Source #

LabelledMember (label :: k) t (Labelled label t) Source #

Reflexivity: t is a member of itself.

Instance details

Defined in Control.Effect.Labelled

Methods

injLabelled :: forall (m :: Type -> Type) a. Labelled label t m a -> Labelled label t m a Source #

Algebra (eff :+: sig) (sub m) => Algebra (Labelled label eff :+: sig) (Labelled label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (Labelled label sub m) -> (Labelled label eff :+: sig) n a -> ctx () -> Labelled label sub m (ctx a) Source #

MonadTrans sub => MonadTrans (Labelled label sub) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

lift :: Monad m => m a -> Labelled label sub m a #

Monad (sub m) => Monad (Labelled label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

(>>=) :: 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 #

return :: a -> Labelled label sub m a #

Functor (sub m) => Functor (Labelled label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

fmap :: (a -> b) -> Labelled label sub m a -> Labelled label sub m b #

(<$) :: a -> Labelled label sub m b -> Labelled label sub m a #

MonadFix (sub m) => MonadFix (Labelled label sub m) Source #

Since: 1.1.1

Instance details

Defined in Control.Effect.Labelled

Methods

mfix :: (a -> Labelled label sub m a) -> Labelled label sub m a #

MonadFail (sub m) => MonadFail (Labelled label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

fail :: String -> Labelled label sub m a #

Applicative (sub m) => Applicative (Labelled label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

pure :: a -> Labelled label sub m a #

(<*>) :: Labelled label sub m (a -> b) -> Labelled label sub m a -> Labelled label sub m b #

liftA2 :: (a -> b -> c) -> Labelled label sub m a -> Labelled label sub m b -> Labelled label sub m c #

(*>) :: 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 #

MonadIO (sub m) => MonadIO (Labelled label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

liftIO :: IO a -> Labelled label sub m a #

Alternative (sub m) => Alternative (Labelled label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

empty :: Labelled label sub m a #

(<|>) :: Labelled label sub m a -> Labelled label sub m a -> Labelled label sub m a #

some :: Labelled label sub m a -> Labelled label sub m [a] #

many :: Labelled label sub m a -> Labelled label sub m [a] #

MonadPlus (sub m) => MonadPlus (Labelled label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

mzero :: Labelled label sub m a #

mplus :: Labelled label sub m a -> Labelled label sub m a -> Labelled label sub m a #

class LabelledMember label (sub :: (Type -> Type) -> Type -> Type) sup | label sup -> sub where Source #

The class of labelled types present in a signature.

Since: 1.0.2.0

Methods

injLabelled :: Labelled label sub m a -> sup m a Source #

Inject a member of a signature into the signature.

Since: 1.0.2.0

Instances

Instances details
LabelledMember label l r => LabelledMember (label :: k) l (l' :+: r) Source #

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 details

Defined in Control.Effect.Labelled

Methods

injLabelled :: forall (m :: Type -> Type) a. Labelled label l m a -> (l' :+: r) m a Source #

LabelledMember (label :: k) l (Labelled label l :+: r) Source #

Left-occurrence: if t is at the head of a signature, we can inject it in O(1).

Instance details

Defined in Control.Effect.Labelled

Methods

injLabelled :: forall (m :: Type -> Type) a. Labelled label l m a -> (Labelled label l :+: r) m a Source #

LabelledMember label t (l1 :+: (l2 :+: r)) => LabelledMember (label :: k) t ((l1 :+: l2) :+: r) Source #

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 details

Defined in Control.Effect.Labelled

Methods

injLabelled :: forall (m :: Type -> Type) a. Labelled label t m a -> ((l1 :+: l2) :+: r) m a Source #

LabelledMember (label :: k) t (Labelled label t) Source #

Reflexivity: t is a member of itself.

Instance details

Defined in Control.Effect.Labelled

Methods

injLabelled :: forall (m :: Type -> Type) a. Labelled label t m a -> Labelled label t m a Source #

type HasLabelled label eff sig m = (LabelledMember label eff sig, Algebra sig m) Source #

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

sendLabelled :: forall label eff sig m a. HasLabelled label eff sig m => eff m a -> m a Source #

Construct a request for a labelled effect to be interpreted by some handler later on.

Since: 1.0.2.0

runUnderLabel :: forall label sub m a. UnderLabel label sub m a -> m a Source #

Since: 1.0.2.0

newtype UnderLabel (label :: k) (sub :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a Source #

A transformer to lift effectful actions to labelled effectful actions.

Since: 1.0.2.0

Constructors

UnderLabel (m a) 

Instances

Instances details
(LabelledMember label sub sig, Algebra sig m) => Algebra (sub :+: sig) (UnderLabel label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (UnderLabel label sub m) -> (sub :+: sig) n a -> ctx () -> UnderLabel label sub m (ctx a) Source #

MonadTrans (UnderLabel sub label) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

lift :: Monad m => m a -> UnderLabel sub label m a #

Monad m => Monad (UnderLabel label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

(>>=) :: 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 #

return :: a -> UnderLabel label sub m a #

Functor m => Functor (UnderLabel label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

fmap :: (a -> b) -> UnderLabel label sub m a -> UnderLabel label sub m b #

(<$) :: a -> UnderLabel label sub m b -> UnderLabel label sub m a #

MonadFix m => MonadFix (UnderLabel label sub m) Source #

Since: 1.1.1

Instance details

Defined in Control.Effect.Labelled

Methods

mfix :: (a -> UnderLabel label sub m a) -> UnderLabel label sub m a #

MonadFail m => MonadFail (UnderLabel label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

fail :: String -> UnderLabel label sub m a #

Applicative m => Applicative (UnderLabel label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

pure :: a -> UnderLabel label sub m a #

(<*>) :: UnderLabel label sub m (a -> b) -> UnderLabel label sub m a -> UnderLabel label sub m b #

liftA2 :: (a -> b -> c) -> UnderLabel label sub m a -> UnderLabel label sub m b -> UnderLabel label sub m c #

(*>) :: 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 #

MonadIO m => MonadIO (UnderLabel label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

liftIO :: IO a -> UnderLabel label sub m a #

Alternative m => Alternative (UnderLabel label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

empty :: UnderLabel label sub m a #

(<|>) :: UnderLabel label sub m a -> UnderLabel label sub m a -> UnderLabel label sub m a #

some :: UnderLabel label sub m a -> UnderLabel label sub m [a] #

many :: UnderLabel label sub m a -> UnderLabel label sub m [a] #

MonadPlus m => MonadPlus (UnderLabel label sub m) Source # 
Instance details

Defined in Control.Effect.Labelled

Methods

mzero :: UnderLabel label sub m a #

mplus :: UnderLabel label sub m a -> UnderLabel label sub m a -> UnderLabel label sub m a #