
On Thu, Aug 09, 2007 at 04:02:05PM +1200, ok wrote:
On 9 Aug 2007, at 8:41 am, David Roundy wrote:
I may be stating the obvious here, but I strongly prefer the do syntax. It's nice to know the other also, but the combination of do +indenting makes complicated code much clearer than the nested parentheses that would be required with purely >>= syntax.
Er, what nested parentheses would those be?
do x1 <- e1 if x1 then do x2 <- e2 xx <- if x2 then e3 else do x4 <- e4 x5 <- e5 e6 x4 x5 e7 xx x1 else do x8 <- e8 x9 <- e9 e10 x8 x9 x1 x11 would become something like e1 >>= \x1 -> if x1 then e2 >>= \x2 -> if x2 then e3 else e4 >>= \x4 -> e5 >>= \x5 -> e6 x4 x5 >>= (flip e7) x1 else e8 >>= \x8 -> e9 >>= \x9 -> e10 x8 x9 x1 >> x11 except that you'd have to figure out where to add parentheses. I'm sure I'd end up writing extra parentheses, but if you put in the minimal number of parentheses, then I doubt I'd be able to read the code. If you only consider the case of trivial code, then you're right, there are no extra parentheses required. This is the beauty of the do notation, it allows one to write actual real complicated monadic code in a form that is actually comprehensible. -- David Roundy Department of Physics Oregon State University