[Haskell-cafe] Re: Monads aren't evil? I think they are.
ross at soi.city.ac.uk
Tue Jan 13 05:45:39 EST 2009
On Tue, Jan 13, 2009 at 10:16:32AM +0000, ChrisK wrote:
> Henning Thielemann wrote:
>> I have seen several libraries where all functions of a monad have the
>> monadic result (), e.g. Binary.Put and other writing functions. This is
>> a clear indicator, that the Monad instance is artificial and was only
>> chosen because of the 'do' notation.
> I completely disagree with that example.
> The Put monad is, mainly, a specialized State monad.
> The internal state being the current fixed-size bytestring memory buffer
> that has been allocated and is being filled.
> The monad make the execution sequential so that there is only one memory
> buffer being filled at a time.
No, Put is a specialized Writer monad. The sequencing is imposed by
the mappend operation of the Builder monoid. The monadic interface is
indeed there just to access do notation. And Henning's general point
also holds: a monad that is always applied to () is just a monoid.
More information about the Haskell-Cafe