
(Moved to haskell-cafe)
Syntacticly, -x parses as 0-x. That is, there is only one - operator and the "0" is filled in when it is encountered in a unary position. Thus
-3 ^ 2 translates to 0 - 3 ^ 2
Slight correction: '-e' is in fact replaced by 'negate e', after fixity resolution, where negate is a method in class Num. The default definition of negate is 'negate x = 0 - x', but there's no requirement that it means this in general. The above example parses as '-(3^2)' because ^ has a higher precedence than unary '-' (8 vs. 7). Translation turns the expression into 'negate (3^2)'. Someone else will have to comment on *why* the precedences are ordered this way, though. Cheers, Simon

Pardon me - I was explaining the intuition rather than the translation. -x is translated to negate x but as far as fixity, you have to appeal to the 0-x notion. The basic idea is that the precedence of unary and infix - are the same in this way. I did a brief search of the old haskell committee mail, but I don't have the definitive message about unary minus around anymore as far as I can see. We seem to have finally given up on the debate by Haskell 1.3. John
participants (2)
-
John Peterson
-
Simon Marlow