Hi all,<div><br></div><div>I was wondering what people thought of a smarter do notation. Currently, there&#39;s an almost trivial desugaring of do notation into (&gt;&gt;=), (&gt;&gt;), and fail (grr!) which seem to naturally imply Monads (although oddly enough, return is never used in the desugaring). The simplicity of the desugaring is nice, but in many cases people write monadic code that could easily have been Applicative.</div>
<div><br></div><div>For example, if I write in a do block:</div><div><br></div><div>x &lt;- action1</div><div>y &lt;- action2</div><div>z &lt;- action3</div><div>return (f x y z)</div><div><br></div><div>that doesn&#39;t require any of the context-sensitivty that Monads give you, and could be processed a lot more efficiently by a clever Applicative instance (a parser, for instance). Furthermore, if return values are ignored, we could use the (&lt;$), (&lt;*), or (*&gt;) operators which could make the whole thing even more efficient in some instances.</div>
<div><br></div><div>Of course, the fact that the return method is explicitly mentioned in my example suggests that unless we do some real voodoo, Applicative would have to be a superclass of Monad for this to make sense. But with the new default superclass instances people are talking about in GHC, that doesn&#39;t seem too unlikely in the near future.</div>
<div><br></div><div>On the implementation side, it seems fairly straightforward to determine whether Applicative is enough for a given do block. Does anyone have any opinions on whether this would be a worthwhile change? The downsides seem to be a more complex desugaring pass (although still something most people could perform in their heads), and some instability with making small changes to the code in a do block. If you make a small change to use a variable before the return, you instantly jump from Applicative to Monad and might break types in your program. I&#39;m not convinced that&#39;s necessary a bad thing, though.</div>
<div><br></div><div>Any thoughts?</div><div><br></div><div>Thanks,</div><div>Dan</div>