
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.