
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