Re: Negation
On Monday 08 February 2010 11:18:07 am Simon Peyton-Jones wrote: 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. I think it's clear what one would expect the result of these expressions to be, but there is some ambiguity considering how GHC parses other similar expressions (I don't actually know if it's following the report in doing so or not). For instance: -4 `mod` 5 parses as: -(4 `mod` 5) which I've seen confuse many a person (and it confused me the first time I saw it; it makes divMod and quotRem appear identical if one is testing them by hand as above, and doesn't know about the weird parsing). Knowing the above, I wasn't entirely sure what the results of x2 and x4 would be. Of course, I think the `mod` parsing is the weird bit, and it'd be good if it could be amended such that -a `mod` -b = (-a) `mod` (-b) like the rest of the proposal. -- Dan ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime
Re: Negation
On Mon, Feb 08, 2010 at 04:18:07PM +, 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
Re: Negation
On Mon, Feb 08, 2010 at 04:59:59PM +, Ross Paterson wrote: But I agree they should all be legal, i.e. that unary minus should bind more tightly than any infix operator (as in C). See also http://hackage.haskell.org/trac/haskell-prime/wiki/NegativeSyntax Thanks Ian ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime
Re: Negation
Måndag 8. februar 2010 17.59.59 skreiv Ross Paterson: But I agree they should all be legal, i.e. that unary minus should bind more tightly than any infix operator (as in C). I second this, at least in general. However, one issue is function application. Should unary minus bind tighter than it or not and are there special cases (spaces)? Consider: 1) foo-1 2) foo -1 3) foo - 1 If unary minus binds tighter than application then we get `foo (-1)` in all cases. The other way around we get `(foo) - (1)` in all cases. To me the most natural parsing would be 1) (foo) - (1) 2) foo (-1) 3) (foo) - (1) Then there's also the issue of literals: 4) 1-1 5) 1 -1 6) 1 - 1 To me, all of these should parse as `(1) - (1)`. I'm a fan of treating literals and variables the same though (referential transparancy even in parsing), and that makes this problematic. Personally I'd like to just get rid of unary minus altogether and use some other symbol, like _, to represent negation, but doing that would probably break most programs out there. -- Sjur Gjøstein Karevoll ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime
Re: Negation
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 +, 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
Re: Negation
On Mon, Feb 08, 2010 at 04:18:07PM +, 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 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. I'm inclined to start a Haskell Prime ticket to fix this language definition bug. But first, can anyone think of a reason *not* to allow all the above? What would be the actual change proposed? If it is something concrete and not something like negatives should be interpreted as unary minus when otherwise it would lead to a parse error then that wouldn't be good. I have enough issues with the layout rule as is :) John -- John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/ ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime
Re: Negation
On Mon, Feb 08, 2010 at 01:24:55PM -0800, John Meacham wrote: What would be the actual change proposed? If it is something concrete and not something like negatives should be interpreted as unary minus when otherwise it would lead to a parse error then that wouldn't be good. I have enough issues with the layout rule as is :) I imagine it would be something like deleting the production lexp6- - exp7 and adding the production exp10- - fexp ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime
RE: Negation
| 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. I'm not sure it's too late to change. That's what Haskell Prime is for. The change would have a flag of course, and could emit a warning if the old and new would give different results. I think I'll create a ticket at least. | I imagine it would be something like deleting the production | | lexp6- - exp7 | | and adding the production | | exp10- - fexp Yes, exactly Simon ___ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime