Am 15.12.2010 08:36, schrieb Roman Cheplyaka: > * Jonathan Geddes <geddes.jonat...@gmail.com> [2010-12-14 19:59:14-0700] >> Quick question: >> >> Why do I need the $ in the following bits of code? >> >>> main = withSocketsDo $ do >>> --do something with sockets >> >>> foo = fromMaybe 0 $ do >>> --do something in the maybe monad >> >> I don't see (after admittedly only a minute or so thinking about it) >> where any grammar ambiguities would be if 'do' had an implicit $ in >> front of it: >> >>> foo = fromMaybe 0 do >>> --do something in maybe >> >> Though now that I've written it down, that is hard for me to visually >> parse at a glance. I'm still curious though. > > Hi Jonathan, > > it's not clear whether you ask how this implies from the standard or > what the rationale of such syntax is. > > Regarding the former, there are two distinct syntactic categories in > Haskell: lexp and aexp. aexp produces all the constructs that can be > used as function arguments and does not include do expressions. lexp is > more broad and produces do expressions as well. Next look at these > productions to see the difference between function application and > operator application (sections 3.3 and 3.4 of 2010 report): > > fexp → [fexp] aexp > > infixexp → lexp qop infixexp > > Regarding the rationale, I'm not so sure and I'd like to hear an > explanation from someone competent. But I assume it has something > to do with the fact that if you supply a 'do' argument, you cannot > supply any more arguments (because 'do' extends to the right as far as > possible). Not that I'm convinced that it is a valid reason to prohibit > such construct.
I made such a proposal 3 years ago, without much feedback. http://www.haskell.org/pipermail/haskell-cafe/2007-July/028203.html Of course, you can supply more arguments, because "do", "let" and "case" will be terminated by layout. This is not true for "\" (lambda) and if-then-else, though. HTH Christian _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe