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

John Meacham john at repetae.net
Tue Aug 30 22:26:37 EDT 2005


On Tue, Aug 30, 2005 at 12:55:55PM +0200, Henning Thielemann wrote:
> 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.

Also, the ability to recognize when something might need to be monadic
or that it will always be pure is a skill you eventually learn as you
use haskell. I know that the same issue bothered me a lot in the past,
but it comes up less and less nowadys. A useful skill is to know the
monad template library well. collecting up a list? use MonadWriter
instead of manually concatting the list and your code is still pure and
often a lot clearer. if you need some other monadic functionality in the
future, it is just a matter of changing a type signature or two and
applying the right monad transformer. the contention isn't between
'monads vs. pure' it is 'uses IO vs. pure', monads, like many powerful
abstractions, are very useful in making pure code more concise, clear
and flexible. 

        John

-- 
John Meacham - ⑆repetae.net⑆john⑈ 


More information about the Haskell-Cafe mailing list