Sure, but it doesn't work the other way; there's no nicer way to write 2.florble(3). So you have a few operator methods, and then other methods are second-class citizens. Which in turn encourages people to abuse the operators as shortcuts for commonly-used operations, á la C++'s <<
In practice, very few languages have suffered problems from operator overloading. I can't think of another language where this is a problem (other than C++), which makes me think it's a cultural/code style problem, rather than a problem with the language itself. C++ seems to encourage abuse because everyone learns its IO library, and its IO has an API design so horrible it should make you retch.
By comparison, I'm not sure that adding more operators makes the resulting code any more palatable. Look at Haskell: libraries define their own operators, and the operators in Haskell have a steep learning curve. Can you tell me, without looking at a chart, whether $ or >>= has higher precedence, and what kind of associativity they have?
No, which is why I don't think that should be allowed. Scala doesn't do that - all "custom operators" have the same precedence, and the global rule is that anything ending in : associates to the right (and is defined by the thing on its right), otherwise to the left. So I could answer those questions easily for a Scala library.
Or am I missing something?
You're right that scala does special-case the precedence of a small number of operators (the list is much shorter than the likes of C, but I still wish we could move away from it).
Io uses Operator Shuffling to move those operator method calls back into normal mathematical expectation (or to be exact... C precedence order) prior to building the AST. Ruby's parser must do (or does) something similar. From lmm answer it sounds like Scala does something similar to Ruby here.
Smalltalk, Self & Rebol have no operator precedence and simply interpret the operators from left to right (using parenthesis to enforce higher precedence).
Some refs:
- http://iolanguage.org/scm/io/docs/IoGuide.html#Syntax-Operat...
map (*2) [1,2,3,4,5]
:)For eg.
1 + 1
is transformed into... add 1 1