[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 07:13:06 EDT 2005


> From: Duncan Coutts [mailto:duncan.coutts at worcester.oxford.ac.uk] 
> 
> This is often a misconception, that just because you find you need to
> 'do' something in the middle of your algorithm, that you need 
> to convert it wholly to monadic style.

Yes. However, Wadler makes a convincing (at least to me) case that the
monadic style is easier to extend. The code changes for the monadic style
appear to be more localised.

Something else I noticed about my non-monadic code was the way I was
threading state through functions. I was tempted to introduce a State monad
to make this easier to manage, but then I decided to try mutable arrays
instead, so that experiment was not attempted. So it might well have been
better in monadic style anyway, even with immutable arrays.

I'm conscious that for most (?) monads, monadic code can be invoked from
non-monadic code. I'm only aware of the IO monad as a one-way trap. So
changing code from pure to monadic doesn't necessarily involve program-wide
changes, unless the monad you're introducing happens to be IO. In my array
example, I introduced STArrays, but the main interface remained pure
(non-monadic), which was my goal.

I was also wondering what the disadvantages of monadic style are? Are there
compiler optimisations which are not possible with monadic code?

Alistair.

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