merits of ApplicativeDo (Was: Monad of no `return` Proposal (MRP): Moving `return` out of `Monad`)

Henning Thielemann lemming at henning-thielemann.de
Mon Oct 19 19:52:28 UTC 2015


On Fri, 2 Oct 2015, Mario Blažević wrote:

> 	The benefits of applicative do, if I understand the motivation 
> correctly, are not so much to help in writing new code intended to be 
> applicative. Instead it lets the programmer write in monadic style and at the 
> same time enables the compiler to convert the code to applicative style if 
> possible. This has the potential to automatically improve performance of 
> legacy Haskell codebase, as well as any new beginner-friendly code that 
> relies on syntactic sugar.

I see the benefit of ApplicativeDo in the short distance of the value 
producer and the value naming. E.g. compare

liftA3
    (\x y z -> complicatedFunc x y z)
    produceX produceY produceZ

and

do x <- produceX
    y <- produceY
    z <- produceZ
    pure $ complicatedFunc x y z


Using the first style you may easily introduce inconsistencies if you 
change the order of produceX, produceY, produceZ, whereas with the second 
style you will certainly change whole lines and stay consistent this way.


More information about the Libraries mailing list