|Version 2 (modified by simonpj@…, 7 years ago) (diff)|
|Dependencies||names of other proposals on which this one depends|
None at present
Which of these definitions are correct Haskell?
x1 = 4 + -5 x2 = -4 + 5 x3 = 4 - -5 x4 = -4 - 5 x5 = 4 * -5 x6 = -4 * 5
Ghc accepts x2, x4, x6 and rejects the others with a message like
Foo.hs:4:7: Precedence parsing error cannot mix `+' [infixl 6] and prefix `-' [infixl 6] in the same infix expression
Hugs and Helium accept them all. I think that Hugs is right here. After all, there is no ambiguity in any of these expressions. And an application-domain user found this behaviour very surprising.
Make unary minus bind more tightly than any other operator. But not more tightly than function application.
External references, papers, articles, support in other languages.
Something like deleting
lexp6 -> - exp7
and adding the production
exp10 -> - fexp
but this relates to Haskell 98 rather than Haskell 2010, so the exact change will differ.