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

Henning Thielemann lemming at henning-thielemann.de
Tue Aug 30 06:55:55 EDT 2005

On Tue, 30 Aug 2005, Bayley, Alistair wrote:

> 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.

The disadvantage of pure functional code is certainly the danger of being
forced to rewrite it to monadic code in the future. But there is a big
advantage of pure functional code: It gives the guarantee about data
dependencies to the user. In many cases Haskell provides a pure functional
way out of the decision "monadic or pure": You can write your functions in
a way that they return intermediate data in some data structure. Then it
is easy to pull them out for output.

More information about the Haskell-Cafe mailing list