effectful-core-2.3.1.0: An easy to use, performant extensible effects library.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Effectful.Labeled

Description

Labeled effects.

Since: 2.3.0.0

Synopsis

Example

An effect can be assigned multiple labels and you can have all of them available at the same time.

>>> import Effectful.Reader.Static
>>> :{
 action
   :: ( Labeled "a" (Reader String) :> es
      , Labeled "b" (Reader String) :> es
      , Reader String :> es
      )
   => Eff es String
 action = do
   a <- labeled @"b" @(Reader String) $ do
     labeled @"a" @(Reader String) $ do
       ask
   b <- labeled @"b" @(Reader String) $ do
     ask
   pure $ a ++ b
:}
>>> :{
 runPureEff @String
   . runLabeled @"a" (runReader "a")
   . runLabeled @"b" (runReader "b")
   . runReader "c"
   $ action
:}
"ab"

Effect

data Labeled (label :: k) (e :: Effect) :: Effect Source #

Assign a label to an effect.

Instances

Instances details
type DispatchOf (Labeled label e) Source # 
Instance details

Defined in Effectful.Labeled

data StaticRep (Labeled label e) Source # 
Instance details

Defined in Effectful.Labeled

data StaticRep (Labeled label e)

Handlers

runLabeled Source #

Arguments

:: forall label e es a b. (Eff (e : es) a -> Eff es b)

The effect handler.

-> Eff (Labeled label e : es) a 
-> Eff es b 

Run a Labeled effect with a given effect handler.

Operations

labeled Source #

Arguments

:: forall label e es a. Labeled label e :> es 
=> Eff (e : es) a

The action using the effect.

-> Eff es a 

Bring an effect into scope to be able to run its operations.