Re: Proposal: require spaces around the dot operator

+1 to the idea of requiring spaces around all operators. It's just good style
Cutting things close syntactically just because you can is perhaps not the best of ideas
Haskell is mathematical both in substance and style. I would not lightly prohibit the use of spacing conventions that have proved over centuries to aid in understanding syntactic strucure. For example, this code fragment to define addition on lists is instantly intelligible. instance Num a => Num [a] where (f:fs) + (g:gs) = f+g : fs+gs But the formula becomes merely an obscure procession of symbols when rewritten with the operators set off by spaces: ( fs : gs ) + ( g : gs ) = f + g : fs + gs And it becomes too long and too subtly modulated to take in at a glance if more spacing is added to emphasize precedence: ( f : fs ) + ( g : gs ) = f + g : fs + gs Doug McIlroy

On Sat, Feb 11, 2012 at 4:07 PM, Doug McIlroy
For example, this code fragment to define addition on lists is instantly intelligible.
instance Num a => Num [a] where (f:fs) + (g:gs) = f+g : fs+gs
But the formula becomes merely an obscure procession of symbols when rewritten with the operators set off by spaces:
( fs : gs ) + ( g : gs ) = f + g : fs + gs
I wouldn't require them inside parentheses, but that's a very good point: the list constructor in patterns is an example of an operator where basically no one ever uses spaces.
And it becomes too long and too subtly modulated to take in at a glance if more spacing is added to emphasize precedence:
( f : fs ) + ( g : gs ) = f + g : fs + gs
I would rather write (f + g) : (fs + gs), but point taken. In any case, while I would in theory support spaces around all operators, modulo counterexamples such as those presented above, I'm not proposing it and I don't think anyone is, so it's probably best to stick to discussing spaces around (.) (which I also support). Apologies for taking the discussion off topic.

Gábor Lehel
In any case, while I would in theory support spaces around all operators, modulo counterexamples such as those presented above, I'm not proposing it and I don't think anyone is, so it's probably best to stick to discussing spaces around (.) (which I also support). Apologies for taking the discussion off topic.
I'm not arguing for or against dot (and postfix) as record selector. I'm not arguing whther or not we should support postfix record selector (whatever the syntax/symbol). But _if_ we want postfix, we need to be sure that it binds tighter than function apply. Some examples (from TDNR observations on 'something odd', and using `?' as postfix field symbol): map toUpper customer?lastName desugar to ===> map toUpper (lastName customer) m?lookup key ===> (lookup m) key No other operator binds tighter than even function apply. So I think the best way to show that is to disallow spaces around the symbol. "It graphically appeals to the notion of a [name] composed of several [name]s." As one poster didn't quite put it. So the advantage of dot from that point of view is: * dot already appears tightly-bound in qualified names * dot is already a reserved operator, so we won't have to search for some other candidate AntC

On Mon, Feb 13, 2012 at 12:07 AM, AntC
So the advantage of dot from that point of view is: * dot already appears tightly-bound in qualified names * dot is already a reserved operator, so we won't have to search for some other candidate
(.) is not a reserved op, it is defined and redefinable like every other operator and has no special fixity rules. main = do let x . y = x + y print (3 . 8) prints 11 like you would expect. Oddly enough, I have occasionally wanted (.) to bind tighter than function application but still be composition. map toUpper.chr xs has a nice feel to me :) John

On Mon, Feb 13, 2012 at 8:41 AM, John Meacham
On Mon, Feb 13, 2012 at 12:07 AM, AntC
wrote: So the advantage of dot from that point of view is: * dot already appears tightly-bound in qualified names * dot is already a reserved operator, so we won't have to search for some other candidate
(.) is not a reserved op, it is defined and redefinable like every other operator and has no special fixity rules.
main = do let x . y = x + y print (3 . 8)
prints 11 like you would expect.
Oddly enough, I have occasionally wanted (.) to bind tighter than function application but still be composition. map toUpper.chr xs has a nice feel to me :)
To that I say: let f = drop 1 . filter odd . take 30 in f xs -- :) -- Ben
participants (5)
-
AntC
-
Ben Millwood
-
Doug McIlroy
-
Gábor Lehel
-
John Meacham