{-# LANGUAGE AllowAmbiguousTypes #-}
module Effectful.Labeled.Writer
(
Writer(..)
, runWriterLocal
, execWriterLocal
, runWriterShared
, execWriterShared
, tell
, listen
, listens
) where
import Effectful
import Effectful.Dispatch.Dynamic
import Effectful.Labeled
import Effectful.Writer.Dynamic (Writer(..))
import Effectful.Writer.Dynamic qualified as W
runWriterLocal
:: forall label w es a
. (HasCallStack, Monoid w)
=> Eff (Labeled label (Writer w) : es)
a -> Eff es (a, w)
runWriterLocal :: forall {k} (label :: k) w (es :: [(Type -> Type) -> Type -> Type])
a.
(HasCallStack, Monoid w) =>
Eff (Labeled label (Writer w) : es) a -> Eff es (a, w)
runWriterLocal = forall (label :: k) (e :: (Type -> Type) -> Type -> Type)
(es :: [(Type -> Type) -> Type -> Type]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
forall {k} (label :: k) (e :: (Type -> Type) -> Type -> Type)
(es :: [(Type -> Type) -> Type -> Type]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
runLabeled @label Eff (Writer w : es) a -> Eff es (a, w)
forall w (es :: [(Type -> Type) -> Type -> Type]) a.
(HasCallStack, Monoid w) =>
Eff (Writer w : es) a -> Eff es (a, w)
W.runWriterLocal
execWriterLocal
:: forall label w es a
. (HasCallStack, Monoid w)
=> Eff (Labeled label (Writer w) : es) a
-> Eff es w
execWriterLocal :: forall {k} (label :: k) w (es :: [(Type -> Type) -> Type -> Type])
a.
(HasCallStack, Monoid w) =>
Eff (Labeled label (Writer w) : es) a -> Eff es w
execWriterLocal = forall (label :: k) (e :: (Type -> Type) -> Type -> Type)
(es :: [(Type -> Type) -> Type -> Type]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
forall {k} (label :: k) (e :: (Type -> Type) -> Type -> Type)
(es :: [(Type -> Type) -> Type -> Type]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
runLabeled @label Eff (Writer w : es) a -> Eff es w
forall w (es :: [(Type -> Type) -> Type -> Type]) a.
(HasCallStack, Monoid w) =>
Eff (Writer w : es) a -> Eff es w
W.execWriterLocal
runWriterShared
:: forall label w es a
. (HasCallStack, Monoid w)
=> Eff (Labeled label (Writer w) : es) a
-> Eff es (a, w)
runWriterShared :: forall {k} (label :: k) w (es :: [(Type -> Type) -> Type -> Type])
a.
(HasCallStack, Monoid w) =>
Eff (Labeled label (Writer w) : es) a -> Eff es (a, w)
runWriterShared = forall (label :: k) (e :: (Type -> Type) -> Type -> Type)
(es :: [(Type -> Type) -> Type -> Type]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
forall {k} (label :: k) (e :: (Type -> Type) -> Type -> Type)
(es :: [(Type -> Type) -> Type -> Type]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
runLabeled @label Eff (Writer w : es) a -> Eff es (a, w)
forall w (es :: [(Type -> Type) -> Type -> Type]) a.
(HasCallStack, Monoid w) =>
Eff (Writer w : es) a -> Eff es (a, w)
W.runWriterShared
execWriterShared
:: forall label w es a
. (HasCallStack, Monoid w)
=> Eff (Labeled label (Writer w) : es) a
-> Eff es w
execWriterShared :: forall {k} (label :: k) w (es :: [(Type -> Type) -> Type -> Type])
a.
(HasCallStack, Monoid w) =>
Eff (Labeled label (Writer w) : es) a -> Eff es w
execWriterShared = forall (label :: k) (e :: (Type -> Type) -> Type -> Type)
(es :: [(Type -> Type) -> Type -> Type]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
forall {k} (label :: k) (e :: (Type -> Type) -> Type -> Type)
(es :: [(Type -> Type) -> Type -> Type]) a b.
HasCallStack =>
(Eff (e : es) a -> Eff es b)
-> Eff (Labeled label e : es) a -> Eff es b
runLabeled @label Eff (Writer w : es) a -> Eff es w
forall w (es :: [(Type -> Type) -> Type -> Type]) a.
(HasCallStack, Monoid w) =>
Eff (Writer w : es) a -> Eff es w
W.execWriterShared
tell
:: forall label w es
. (HasCallStack, Labeled label (Writer w) :> es)
=> w
-> Eff es ()
tell :: forall {k} (label :: k) w (es :: [(Type -> Type) -> Type -> Type]).
(HasCallStack, Labeled label (Writer w) :> es) =>
w -> Eff es ()
tell = Labeled label (Writer w) (Eff es) () -> Eff es ()
forall (e :: (Type -> Type) -> Type -> Type)
(es :: [(Type -> Type) -> Type -> Type]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (Labeled label (Writer w) (Eff es) () -> Eff es ())
-> (w -> Labeled label (Writer w) (Eff es) ()) -> w -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (label :: k) (e :: (Type -> Type) -> Type -> Type)
(a :: Type -> Type) b.
e a b -> Labeled label e a b
forall {k} (label :: k) (e :: (Type -> Type) -> Type -> Type)
(a :: Type -> Type) b.
e a b -> Labeled label e a b
Labeled @label (Writer w (Eff es) () -> Labeled label (Writer w) (Eff es) ())
-> (w -> Writer w (Eff es) ())
-> w
-> Labeled label (Writer w) (Eff es) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. w -> Writer w (Eff es) ()
forall w (a :: Type -> Type). w -> Writer w a ()
Tell
listen
:: forall label w es a
. (HasCallStack, Labeled label (Writer w) :> es)
=> Eff es a
-> Eff es (a, w)
listen :: forall {k} (label :: k) w (es :: [(Type -> Type) -> Type -> Type])
a.
(HasCallStack, Labeled label (Writer w) :> es) =>
Eff es a -> Eff es (a, w)
listen = Labeled label (Writer w) (Eff es) (a, w) -> Eff es (a, w)
forall (e :: (Type -> Type) -> Type -> Type)
(es :: [(Type -> Type) -> Type -> Type]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (Labeled label (Writer w) (Eff es) (a, w) -> Eff es (a, w))
-> (Eff es a -> Labeled label (Writer w) (Eff es) (a, w))
-> Eff es a
-> Eff es (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (label :: k) (e :: (Type -> Type) -> Type -> Type)
(a :: Type -> Type) b.
e a b -> Labeled label e a b
forall {k} (label :: k) (e :: (Type -> Type) -> Type -> Type)
(a :: Type -> Type) b.
e a b -> Labeled label e a b
Labeled @label (Writer w (Eff es) (a, w)
-> Labeled label (Writer w) (Eff es) (a, w))
-> (Eff es a -> Writer w (Eff es) (a, w))
-> Eff es a
-> Labeled label (Writer w) (Eff es) (a, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff es a -> Writer w (Eff es) (a, w)
forall (a :: Type -> Type) a1 w. a a1 -> Writer w a (a1, w)
Listen
listens
:: forall label w es a b
. (HasCallStack, Labeled label (Writer w) :> es)
=> (w -> b)
-> Eff es a
-> Eff es (a, b)
listens :: forall {k} (label :: k) w (es :: [(Type -> Type) -> Type -> Type])
a b.
(HasCallStack, Labeled label (Writer w) :> es) =>
(w -> b) -> Eff es a -> Eff es (a, b)
listens w -> b
f Eff es a
m = do
(a
a, w
w) <- forall (label :: k) w (es :: [(Type -> Type) -> Type -> Type]) a.
(HasCallStack, Labeled label (Writer w) :> es) =>
Eff es a -> Eff es (a, w)
forall {k} (label :: k) w (es :: [(Type -> Type) -> Type -> Type])
a.
(HasCallStack, Labeled label (Writer w) :> es) =>
Eff es a -> Eff es (a, w)
listen @label Eff es a
m
(a, b) -> Eff es (a, b)
forall a. a -> Eff es a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (a
a, w -> b
f w
w)