Control.Monad.Writer.Strict not as strict as expected

Edward Kmett ekmett at gmail.com
Thu Sep 15 23:02:17 CEST 2011


On Thu, Sep 15, 2011 at 4:43 PM, Matt Brown <matt at softmechanics.net> wrote:

> Hello all,
>
> I've been debugging a space leak, and believe I've traced it to a
> chain of unevaluated calls to mappend in the bind operator for
> Control.Monad.Writer.Strict.  I had expected these calls to be
> evaluated strictly by the strict Writer, but it doesn't seem to be the
> case.  Am I understanding this correctly?


The Strict in Control.Monad.Writer.Strict refers to the fact that the tuple
is matched strictly -- not the Monoid.


> If so, is this the intended
> behavior?
>

The Strict/Lazy writer split has nothing to do with the strictness of your
monoid, but rather whether or not operations such as:

> fmap f ~(w, a) = (w, f a)

or

> fmap f (w, a) = (w, f a)

are used throughout the API. We default to Lazy because slightly more code
can terminate (at least in the case of State), lthough some would challenge
that due to the behavior in the presence of bottoms the Strict versions are
more correct.

Neither of these are, or are intended to be, the monad you are looking for.

-Edward Kmett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20110915/0288765b/attachment.htm>


More information about the Libraries mailing list