effectful-core
Safe HaskellSafe-Inferred
LanguageGHC2021

Effectful.Labeled.Writer

Description

Convenience functions for the Labeled Writer effect.

Since: 2.4.0.0

Synopsis

Effect

data Writer w :: Effect where Source #

Provide access to a write only value of type w.

Constructors

Tell :: w -> Writer w m () 
Listen :: m a -> Writer w m (a, w) 

Instances

Instances details
type DispatchOf (Writer w) Source # 
Instance details

Defined in Effectful.Internal.Effect.Dynamic

Handlers

Local

runWriterLocal :: forall label w es a. (HasCallStack, Monoid w) => Eff (Labeled label (Writer w) : es) a -> Eff es (a, w) Source #

Run the Writer effect and return the final value along with the final output (via Effectful.Writer.Static.Local).

execWriterLocal :: forall label w es a. (HasCallStack, Monoid w) => Eff (Labeled label (Writer w) : es) a -> Eff es w Source #

Run a Writer effect and return the final output, discarding the final value (via Effectful.Writer.Static.Local).

Shared

runWriterShared :: forall label w es a. (HasCallStack, Monoid w) => Eff (Labeled label (Writer w) : es) a -> Eff es (a, w) Source #

Run the Writer effect and return the final value along with the final output (via Effectful.Writer.Static.Shared).

execWriterShared :: forall label w es a. (HasCallStack, Monoid w) => Eff (Labeled label (Writer w) : es) a -> Eff es w Source #

Run the Writer effect and return the final output, discarding the final value (via Effectful.Writer.Static.Shared).

Operations

tell :: forall label w es. (HasCallStack, Labeled label (Writer w) :> es) => w -> Eff es () Source #

Append the given output to the overall output of the Writer.

listen :: forall label w es a. (HasCallStack, Labeled label (Writer w) :> es) => Eff es a -> Eff es (a, w) Source #

Execute an action and append its output to the overall output of the Writer.

listens :: forall label w es a b. (HasCallStack, Labeled label (Writer w) :> es) => (w -> b) -> Eff es a -> Eff es (a, b) Source #

Execute an action and append its output to the overall output of the Writer, then return the final value along with a function of the recorded output.

listens f m ≡ second f <$> listen m

Re-exports

newtype Labeled (label :: k) (e :: Effect) :: Effect where Source #

Assign a label to an effect.

Note: labeled effects are best used together with the effectful-plugin package, as it significantly improves their usability.

The constructor is for sending labeled operations of a dynamically dispatched effect to the handler:

>>> import Effectful.Dispatch.Dynamic
>>> :{
  data X :: Effect where
    X :: X m Int
  type instance DispatchOf X = Dynamic
:}
>>> :{
  runPureEff . runLabeled @"x" (interpret_ $ \X -> pure 333) $ do
    send $ Labeled @"x" X
:}
333

Constructors

Labeled :: forall label e m a. e m a -> Labeled label e m a

Since: 2.4.0.0

Instances

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

Defined in Effectful.Labeled

type DispatchOf (Labeled label e) = DispatchOf e
data StaticRep (Labeled label e) Source # 
Instance details

Defined in Effectful.Labeled

data StaticRep (Labeled label e)