tell-0.1: The MonadTell class and related monad transformers.
Copyright(C) 2021 Isaac Elliott
LicenseBSD-3 (see the file LICENSE)
MaintainerIsaac Elliott <isaace71295@gmail.com>
Safe HaskellNone
LanguageHaskell2010

Control.Monad.Tell.Class

Description

 
Synopsis

Documentation

class (Monoid w, Monad m) => MonadTell w m | m -> w where Source #

Laws

tell mempty ≡ pure ()
tell (a <> b) ≡ tell a *> tell b

How does this relate to MonadWriter?

MonadTell is a generalisation of MonadWriter. It only provides tell; a function that 'appends' a monoidal value to some output. Morally, we have class MonadTell w m => MonadWriter w m where .... See WrappedMonadWriter for the witness of this.

MonadWriter's listen and pass functions require the monad to hold onto the output for an arbitrarily long time. This can cause applications to use memory linear in the number of tells, when constant memory usage would suffice.

A motivating example is writing monoidal results to a file. Using MonadWriter (via a WriterT), you would have to accumulate the the entire output and then write it to the file. In contrast, MonadTell allows you to write each result to the file as it's obtained, allowing the result to be freed while the rest of the program runs.

Minimal complete definition

Nothing

Methods

tell :: w -> m () Source #

default tell :: (m ~ t n, MonadTrans t, MonadTell w n) => w -> m () Source #

Instances

Instances details
MonadWriter w m => MonadTell w (WrappedMonadWriter m) Source # 
Instance details

Defined in Control.Monad.Tell.Class

Methods

tell :: w -> WrappedMonadWriter m () Source #

MonadTell w m => MonadTell w (MaybeT m) Source # 
Instance details

Defined in Control.Monad.Tell.Class

Methods

tell :: w -> MaybeT m () Source #

MonadTell w m => MonadTell w (StateT s m) Source # 
Instance details

Defined in Control.Monad.Tell.Class

Methods

tell :: w -> StateT s m () Source #

MonadTell w m => MonadTell w (StateT s m) Source # 
Instance details

Defined in Control.Monad.Tell.Class

Methods

tell :: w -> StateT s m () Source #

MonadTell w m => MonadTell w (SelectT r m) Source # 
Instance details

Defined in Control.Monad.Tell.Class

Methods

tell :: w -> SelectT r m () Source #

MonadTell w m => MonadTell w (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Tell.Class

Methods

tell :: w -> ReaderT r m () Source #

MonadTell w m => MonadTell w (IdentityT m) Source # 
Instance details

Defined in Control.Monad.Tell.Class

Methods

tell :: w -> IdentityT m () Source #

(MonadTell w m, Monoid s) => MonadTell w (AccumT s m) Source # 
Instance details

Defined in Control.Monad.Tell.Class

Methods

tell :: w -> AccumT s m () Source #

(Monoid w, Monad m) => MonadTell w (WriterT w m) Source # 
Instance details

Defined in Control.Monad.Tell.Class

Methods

tell :: w -> WriterT w m () Source #

(Monoid w, Monad m) => MonadTell w (WriterT w m) Source # 
Instance details

Defined in Control.Monad.Tell.Class

Methods

tell :: w -> WriterT w m () Source #

(Monoid w, Monad m) => MonadTell w (WriterT w m) Source # 
Instance details

Defined in Control.Monad.Tell.Class

Methods

tell :: w -> WriterT w m () Source #

(Monoid w, MonadIO m) => MonadTell w (HandleWriterT w m) Source #

The MonadTell law tell (a <> b) ≡ tell a *> tell b is only obeyed when the Handle is written to by a single thread.

Instance details

Defined in Control.Monad.Trans.HandleWriter

Methods

tell :: w -> HandleWriterT w m () Source #

MonadTell w m => MonadTell w (ContT r m) Source # 
Instance details

Defined in Control.Monad.Tell.Class

Methods

tell :: w -> ContT r m () Source #

(Monoid w, Monad m) => MonadTell w (RWST r w s m) Source # 
Instance details

Defined in Control.Monad.Tell.Class

Methods

tell :: w -> RWST r w s m () Source #

(Monoid w, Monad m) => MonadTell w (RWST r w s m) Source # 
Instance details

Defined in Control.Monad.Tell.Class

Methods

tell :: w -> RWST r w s m () Source #

(Monoid w, Monad m) => MonadTell w (RWST r w s m) Source # 
Instance details

Defined in Control.Monad.Tell.Class

Methods

tell :: w -> RWST r w s m () Source #

newtype WrappedMonadWriter m a Source #

A proof that a MonadWriter instance implies a MonadTell instance.

Constructors

WrappedMonadWriter 

Fields