{-# LANGUAGE DeriveFunctor, ExistentialQuantification, RankNTypes, StandaloneDeriving #-}
module Control.Effect.Writer
(
Writer(..)
, tell
, listen
, listens
, censor
, Algebra
, Effect
, Has
, run
) where
import Control.Algebra
import Control.Effect.Writer.Internal (Writer(..))
tell :: Has (Writer w) sig m => w -> m ()
tell :: w -> m ()
tell w :: w
w = Writer w m () -> m ()
forall (eff :: (* -> *) -> * -> *) (sig :: (* -> *) -> * -> *)
(m :: * -> *) a.
(Member eff sig, Algebra sig m) =>
eff m a -> m a
send (w -> m () -> Writer w m ()
forall w (m :: * -> *) k. w -> m k -> Writer w m k
Tell w
w (() -> m ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()))
{-# INLINE tell #-}
listen :: Has (Writer w) sig m => m a -> m (w, a)
listen :: m a -> m (w, a)
listen m :: m a
m = Writer w m (w, a) -> m (w, a)
forall (eff :: (* -> *) -> * -> *) (sig :: (* -> *) -> * -> *)
(m :: * -> *) a.
(Member eff sig, Algebra sig m) =>
eff m a -> m a
send (m a -> (w -> a -> m (w, a)) -> Writer w m (w, a)
forall w (m :: * -> *) k a. m a -> (w -> a -> m k) -> Writer w m k
Listen m a
m (((w, a) -> m (w, a)) -> w -> a -> m (w, a)
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (w, a) -> m (w, a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure))
{-# INLINE listen #-}
listens :: Has (Writer w) sig m => (w -> b) -> m a -> m (b, a)
listens :: (w -> b) -> m a -> m (b, a)
listens f :: w -> b
f m :: m a
m = Writer w m (b, a) -> m (b, a)
forall (eff :: (* -> *) -> * -> *) (sig :: (* -> *) -> * -> *)
(m :: * -> *) a.
(Member eff sig, Algebra sig m) =>
eff m a -> m a
send (m a -> (w -> a -> m (b, a)) -> Writer w m (b, a)
forall w (m :: * -> *) k a. m a -> (w -> a -> m k) -> Writer w m k
Listen m a
m (((b, a) -> m (b, a)) -> b -> a -> m (b, a)
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (b, a) -> m (b, a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b -> a -> m (b, a)) -> (w -> b) -> w -> a -> m (b, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. w -> b
f))
{-# INLINE listens #-}
censor :: Has (Writer w) sig m => (w -> w) -> m a -> m a
censor :: (w -> w) -> m a -> m a
censor f :: w -> w
f m :: m a
m = Writer w m a -> m a
forall (eff :: (* -> *) -> * -> *) (sig :: (* -> *) -> * -> *)
(m :: * -> *) a.
(Member eff sig, Algebra sig m) =>
eff m a -> m a
send ((w -> w) -> m a -> (a -> m a) -> Writer w m a
forall w (m :: * -> *) k a.
(w -> w) -> m a -> (a -> m k) -> Writer w m k
Censor w -> w
f m a
m a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure)
{-# INLINE censor #-}