Version 1 (modified by Simon Peyton Jones, 7 years ago) (diff)

Proposal: NegationBindsTightly

Ticket #999
Dependencies names of other proposals on which this one depends
Related NegativeSyntax

Compiler support

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

    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.

Report Delta

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.