[Haskell-cafe] Re: Monads aren't evil? I think they are.

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Tue Jan 13 19:58:48 EST 2009


On Tue, 2009-01-13 at 19:44 -0500, Dan Doel wrote:
> On Tuesday 13 January 2009 7:27:10 pm Luke Palmer wrote:
> > > When GHC starts optimizing (Writer Builder) as well as it optimizes PutM,
> > > then
> > > that will be a cogent argument. Until then, one might argue that it
> > > misses "the whole point of Put".
> >
> > Well it can still serve as an optimization over bytestrings using whatever
> > trickery it uses (I am assuming here -- I am not familiar with its
> > trickery), the same way DList is an optimization over List.  It's just that
> > its  monadiness is superfluous.
> >
> > Surely PutM and Writer Put have almost the same performance?!  (I am
> > worried if not -- if not, can you give an indication why?)
> 
> The underlying monoid is Builder. The point of PutM is to be a version of 
> Writer that's specialized to the Builder monoid for maximum performance. It 
> looks like:
> 
>   data PairS a = PairS a {-# UNPACK #-} !Builder
> 
>   newtype PutM a = Put { unPut :: PairS a }
> 
> I'm not sure why it's split up like that. Anyhow, the strict, unpacked Builder 
> gets optimized better than Writer Builder.

Oops, I walked into this conversation without reading enough context.
Sorry, I see what you mean now.

Yes, it's specialised to get decent performance. As you say, the lifted
(,) in the Writer would get in the way otherwise.

There's an interesting project in optimising parametrised monads and
stacks of monad transformers.

Duncan



More information about the Haskell-Cafe mailing list