class (Monoid w, Monad m, HasSink tag w m) => HasWriter (tag :: k) w (m :: Type -> Type) | tag m -> w whereWriter capability
An instance should fulfill the following laws. At this point these laws are not definitive, see https://github.com/haskell/mtl/issues/5.
listen @t (pure a) = pure (a, mempty)listen @t (tell @t w) = tell @t w >> pure (w, w)listen @t (m >>= k) = listen @t m >>= \(a, w1) -> listen @t (k a) >>= \(b, w2) -> pure (b, w1 `mappend` w2)pass @t (tell @t w >> pure (a, f)) = tell @t (f w) >> pure awriter @t (a, w) = tell @t w >> pure aA note on the HasSink super class.
HasSink offers one yield method with the same signature as tell.
Many people's intuition, however, wouldn't connect the two: yielding
tosses the value down some black-box chute, while telling grows and
accumulation via the monoid. The connection is since the chute is opaque,
the tosser cannot rule out there being such an accumulation at the chutes
other end.
Formally, we reach the same conclusion. HasSink has no laws,
indicating the user can make no assumptions beyond the signature of yield.
HasWriter, with tell defined as yield, is thus always compatable
regardless of whatever additional methods it provides and laws by which it
abides.
Methods
Instances5HasSink, HasWriter, Reified
(Monoid w, HasState tag w m) => HasWriter tag w (WriterLog m)Defined in capability-0.5.0.1 · Capability.Writer(Monoid w, Monad m, Reifies s (Reified tag (HasWriter tag w) m)) => HasSink tag w (Reflected s (HasWriter tag w) m)Defined in capability-0.5.0.1 · Capability.Writer(forall x. Coercible (m x) (t2 (t1 m) x), Monad m, HasWriter tag w (t2 (t1 m))) => HasWriter tag w ((:.:) t2 t1 m)Defined in capability-0.5.0.1 · Capability.WriterCompose two accessors.
(Monad m, Monoid w, Reifies s (Reified tag (HasWriter tag w) m)) => HasWriter tag w (Reflected s (HasWriter tag w) m)Defined in capability-0.5.0.1 · Capability.Writerdata Reified tag (HasWriter tag w)ReifiedWriter_writerSink :: Reified tag (HasSink tag w) m_writer :: forall a. (a, w) -> m a_listen :: forall a. m a -> m (a, w)_pass :: forall a. m (a, w -> w) -> m a