{-# LANGUAGE AllowAmbiguousTypes #-}
module Data.Effect.Writer where
data Tell w a where
Tell :: w -> Tell w ()
data WriterH w f a where
Listen :: f a -> WriterH w f (w, a)
Censor :: (w -> w) -> f a -> WriterH w f a
makeEffect [''Tell] [''WriterH]
pass :: (Tell w <: m, WriterH w <<: m, Monad m) => m (w -> w, a) -> m a
pass :: forall w (m :: * -> *) a.
(Tell w <: m, WriterH w <<: m, Monad m) =>
m (w -> w, a) -> m a
pass m (w -> w, a)
m = do
(w
w, (w -> w
f, a
a)) <- forall a w (f :: * -> *). SendSig (WriterH w) f => f a -> f (w, a)
listen m (w -> w, a)
m
forall w (f :: * -> *). SendIns (Tell w) f => w -> f ()
tell forall a b. (a -> b) -> a -> b
$ w -> w
f w
w
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a