referential transparency? (for fixity of local operators)

I was really surprised at the following: *Main> 1 + 2 * 3 7 *Main> ( \ (+) (*) -> 1 + 2 * 3 ) (+) (*) 9 because I was somehow assuming that either a) the Prelude fixities of the operators are kept b) or they are undefined, so the parser rejects. but the Haskell standard says "Any operator lacking a fixity declaration is assumed to be infixl 9". This really should be "infix 9"?

* Johannes Waldmann
I was really surprised at the following:
*Main> 1 + 2 * 3 7
*Main> ( \ (+) (*) -> 1 + 2 * 3 ) (+) (*) 9
because I was somehow assuming that either
a) the Prelude fixities of the operators are kept b) or they are undefined, so the parser rejects.
but the Haskell standard says "Any operator lacking a fixity declaration is assumed to be infixl 9". This really should be "infix 9"?
This behaviour is really handy when you use functions as operators (using backticks notation). They typically lack infix annotations, but having to put parentheses would be very annoying. Roman

Compile with -Wall and the flaw becomes obvious:
<interactive>:2:5:
Warning: This binding for `+' shadows the existing binding
imported from `Prelude' (and originally defined in `GHC.Num')
<interactive>:2:9:
Warning: This binding for `*' shadows the existing binding
imported from `Prelude' (and originally defined in `GHC.Num')
<interactive>:2:16:
Warning: Defaulting the following constraint(s) to type `Integer'
(Num a0) arising from the literal `1'
In the first argument of `(+)', namely `1'
In the first argument of `(*)', namely `1 + 2'
In the expression: 1 + 2 * 3
<interactive>:2:16:
Warning: Defaulting the following constraint(s) to type `Integer'
(Num a0) arising from the literal `1' at <interactive>:2:16
(Show a0) arising from a use of `print' at
<interactive>:2:1-34
In the first argument of `(+)', namely `1'
In the first argument of `(*)', namely `1 + 2'
In the expression: 1 + 2 * 3
Shadowing is bad, and tends (as in this case) to be confusing.
- Clark
On Fri, Oct 5, 2012 at 7:22 AM, Roman Cheplyaka
* Johannes Waldmann
[2012-10-05 11:11:48+0000] I was really surprised at the following:
*Main> 1 + 2 * 3 7
*Main> ( \ (+) (*) -> 1 + 2 * 3 ) (+) (*) 9
because I was somehow assuming that either
a) the Prelude fixities of the operators are kept b) or they are undefined, so the parser rejects.
but the Haskell standard says "Any operator lacking a fixity declaration is assumed to be infixl 9". This really should be "infix 9"?
This behaviour is really handy when you use functions as operators (using backticks notation). They typically lack infix annotations, but having to put parentheses would be very annoying.
Roman
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 10/5/12 7:11 AM, Johannes Waldmann wrote:
I was really surprised at the following:
*Main> 1 + 2 * 3 7
*Main> ( \ (+) (*) -> 1 + 2 * 3 ) (+) (*) 9
because I was somehow assuming that either
a) the Prelude fixities of the operators are kept
After dealing with how Coq handles infix operators, I'm profoundly glad that Haskell doesn't do this. The fixity of an operator is a property of the operator itself, not of the notation used to display the operator. There's no reason for my (+) operator to have the same fixity as your (+) operator, regardless of whether we happen to use the same notation or not.
b) or they are undefined, so the parser rejects.
but the Haskell standard says "Any operator lacking a fixity declaration is assumed to be infixl 9". This really should be "infix 9"?
Yep, default fixity. As Roman Cheplyaka mentioned, this is especially helpful for ad hoc uses of backticks. (For non-adhoc uses, it's best to give an explicit fixity just like for other infix operators.) As for whether the default should be "infix 9" instead of "infixl 9", I dunno... -- Live well, ~wren

On 12-10-06 05:18 AM, Johannes Waldmann wrote:
wren ng thornton
writes: As for whether the default should be "infix 9" instead of "infixl 9" ...
that was exactly the point of my message. - J.
Perhaps, half of the people want infixl, another half of the people want infixr, and so at the end the middle ground of neither l nor r is taken. Perhaps, political decision is about saying no to both the left and the right? :)
participants (5)
-
Albert Y. C. Lai
-
Clark Gaebel
-
Johannes Waldmann
-
Roman Cheplyaka
-
wren ng thornton