[Haskell-cafe] Monadic vs "pure" style (was: pros and cons of sta tic typing and side effects)

Bayley, Alistair Alistair_Bayley at ldn.invesco.com
Tue Aug 30 06:08:36 EDT 2005

> From: Martin Vlk [mailto:vlcak01 at tiscali.cz] 


This quote from the paper resonated with me:

"Also, if
imperative elements of a given application were not taken
into account during its design but turn out to be necessary
later on, often major parts have to be redesigned or
(at least) reimplemented, especially because types change
significantly. A simple but recurring example is to add
printing of status information to an otherwise purely
functional algorithm. In the worst case this could result
in having to rewrite the algorithm in a monadic style, but
also to rewrite its callers (and transitively their callers
as well), plus adjusting all type annotations on the way.
Even when using opaque accessors to data structures, the
required changes cannot necessarily be limited to a single
module, but affect large parts of the system."

The difficulty seems to be when you want to turn code that was initially
"pure" into monadic code: it requires a fairly substantial rewrite. Once in
a monadic style, I expect it is much easier to add various
monadic/imperative enhancements.

I've experienced this recently, where I've converted an algorithm from a
purely functional version, using immutable arrays, to a monadic version
using destructive arrays. I introduced errors with the conversion, and the
unit test suite that I had for the pure version also had to be converted to
a monadic style, in order to test the now-monadic code. So having to perform
this conversion is clearly undesirable.

I'm reminded of Wadler's "Monads for functional programming"
) where he illustrates how easy it is to extend a program written in a
mondadic style.

So this begs the question: how much should we stick to a purely functional
style? Should we advocate the adoption of a more monadic style from the
outset, for programmers new to Haskell too?


Confidentiality Note: The information contained in this   message, and any
attachments, may contain confidential   and/or privileged material. It is
intended solely for the   person(s) or entity to which it is addressed. Any
review,   retransmission, dissemination, or taking of any action in
reliance upon this information by persons or entities other   than the
intended recipient(s) is prohibited. If you received  this in error, please
contact the sender and delete the   material from any computer.

More information about the Haskell-Cafe mailing list