
29 Aug
2001
29 Aug
'01
11:16 a.m.
(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