Of course unary minus should bind tighter than any infix operator. I remember suggesting this when the language was designed, but the Haskell committee was very set against it (mostly Joe Fasel I think).
I think it's too late to change that now, it could really introduce some subtle bugs with no parse or type errors. On Mon, Feb 8, 2010 at 5:59 PM, Ross Paterson <r...@soi.city.ac.uk> wrote: > On Mon, Feb 08, 2010 at 04:18:07PM +0000, Simon Peyton-Jones wrote: >> 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 accepts them all. >> >> I believe that the language specifies that all should be rejected. >> http://haskell.org/onlinereport/syntax-iso.html > > I think GHC conforms to the Report; here is the relevant part of the grammar: > > exp6 -> exp7 > | lexp6 > lexp6 -> (lexp6 | exp7) + exp7 > | (lexp6 | exp7) - exp7 > | - exp7 > > exp7 -> exp8 > | lexp7 > lexp7 -> (lexp7 | exp8) * exp8 > > But I agree they should all be legal, i.e. that unary minus should bind > more tightly than any infix operator (as in C). Note that Hugs does > not do that: > > Hugs> -5 `mod` 2 > -1 > Hugs> (-5) `mod` 2 > 1 > Hugs> -(5 `mod` 2) > -1 > _______________________________________________ > Haskell-prime mailing list > Haskell-prime@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-prime > _______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime