{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE RankNTypes #-}
module Control.Effect.Writer
(
Writer(..)
, tell
, listen
, listens
, censor
, Algebra
, Has
, run
) where
import Control.Algebra
import Control.Effect.Writer.Internal (Writer(..))
import Data.Bifunctor (first)
tell :: Has (Writer w) sig m => w -> m ()
tell :: forall w (sig :: (* -> *) -> * -> *) (m :: * -> *).
Has (Writer w) sig m =>
w -> m ()
tell w
w = Writer w m () -> m ()
forall (eff :: (* -> *) -> * -> *) (sig :: (* -> *) -> * -> *)
(m :: * -> *) a.
(Member eff sig, Algebra sig m) =>
eff m a -> m a
send (w -> Writer w m ()
forall w (m :: * -> *). w -> Writer w m ()
Tell w
w)
{-# INLINE tell #-}
listen :: Has (Writer w) sig m => m a -> m (w, a)
listen :: forall w (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Writer w) sig m =>
m a -> m (w, a)
listen 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 -> Writer w m (w, a)
forall (m :: * -> *) a w. m a -> Writer w m (w, a)
Listen m a
m)
{-# INLINE listen #-}
listens :: Has (Writer w) sig m => (w -> b) -> m a -> m (b, a)
listens :: forall w (sig :: (* -> *) -> * -> *) (m :: * -> *) b a.
Has (Writer w) sig m =>
(w -> b) -> m a -> m (b, a)
listens w -> b
f = ((w, a) -> (b, a)) -> m (w, a) -> m (b, a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((w -> b) -> (w, a) -> (b, a)
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first w -> b
f) (m (w, a) -> m (b, a)) -> (m a -> m (w, a)) -> m a -> m (b, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> m (w, a)
forall w (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Writer w) sig m =>
m a -> m (w, a)
listen
{-# INLINE listens #-}
censor :: Has (Writer w) sig m => (w -> w) -> m a -> m a
censor :: forall w (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has (Writer w) sig m =>
(w -> w) -> m a -> m a
censor w -> w
f 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 -> Writer w m a
forall w (m :: * -> *) k. (w -> w) -> m k -> Writer w m k
Censor w -> w
f m a
m)
{-# INLINE censor #-}