
On Fri, 2010-10-08 at 01:13 +0300, Lauri Alanko wrote:
Your "general" rule doesn't subsume your case example, since a case expression is not an application. I think you mean something like
do C[(<- m)] => m >>= \tmp -> C[tmp]
where C is an arbitrary expression context. It could further be generalized to allow several (<- ...) subterms in an expression, with implied left-to right sequencing.
Yes, that's what I meant. Thanks for describing it properly. On Fri, 2010-10-08 at 05:41 -0700, Nicolas Pouillard wrote:
Imagine find this code:
do s1 C[(<- s2)]
And I don't see the (<- s2) in C, and so I refactor it as:
s1 >> C[(<- s2)]
This is roughly what I meant with "abused": Where "C" is very complex, it might become non-obvious where exactly the monad actions are supposed to happen. Hence such traps when refactoring. Also of note: Just moving sub-expressions around isn't something that is guaranteed to be save. Introducing new names and using them in "s2" would be problematic, for example: do map (\x -> (<- putStrLn x)) ["a", "b"] Obviously can't be made to work. You might have to check for this - or maybe even disallow the shorthand inside lamdbas and lets. Might be less satisfying to have such special cases, but it is still a good bit more general than what is available right now. Greetings, Peter Wortmann