[Haskell-cafe] generalizing the writer monad

Petr P petr.mvd at gmail.com
Wed Oct 24 10:10:02 CEST 2012


thanks for your interesting ideas an inspiring answers.

However I meant something a bit different. My point wasn't how to
implement this problem with the current set of tools. Instead, I was
wondering if it'd be worth expanding the current Reader/Writer

  Best regards,

2012/10/18 Strake <strake888 at gmail.com>:
>  On 17/10/2012, Petr P <petr.mvd at gmail.com> wrote:
>>     Hi,
>> (this is a literate Haskell post.)
>> lately I was playing with the Writer monad and it seems to me that it
>> is too tightly coupled with monoids. Currently, MonadWriter makes the
>> following assumptions:
>> (1) The written value can be read again later.
>> (2) For that to be possible it has to be monoid so that multiple (or
>> zero) values can be combined.
>> I fell say that this is a bit restricting. Sometimes, the written
>> value can be lost - either used to compute something else or for
>> example sent out using some IO action to a file, network etc. For
>> example, I'd like to create an IO-based writer monad whose `tell` logs
>> its argument somewhere - prints it, stores to a file etc.
> No need:
> newtype SequenceM m a = SequenceM (m a);
> instance (Monad m, Monoid a) => Monoid (SequenceM m a) where {
>   mempty = SequenceM (return mempty);
>   SequenceM mx `mappend` SequenceM my = SequenceM (liftM2 mappend mx my);
> }
> whatever :: (MonadWriter (SequenceM IO ()) m) => m ();
> whatever = tell (SequenceM (someIO :: IO ()));
> Cheers,
> Strake
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list