I'd like to create a BigInteger class that would handle arbitrary precision integer operation. There are a few hooks I'd like:
Integer = require('./BigInteger')
1 + 3
1 == 3
Is there anything preventing coffeescript from supporting this?
It's certainly possible, but without a static type system, it's not possible to overload operators selectively. Every single instance of ==, + etc, would have to be compiled into a function call, whether or not its operands were actually BigIntegers. The performance penalty would be crushing, and would apply to the entire program. Also, the overloaded operator definitions would need to explicitly deal with every JS type they might receive -- strings, booleans, objects, and native numbers, in addition to the custom type you wish to dispatch. Since types are unknown until runtime, the compiler would not be able to help.
Interoperability is another concern. Even if BigIntegers behaved exactly like real Number values within your code, they would still look like Objects to the runtime. You couldn't pass them to external JS libraries or to native methods who expected an actual number. Again, this is not something the compiler could remedy.
For more discussion, see #727.
Conclusion, for lost wanderers, on this issue:
(Jeremy's postion stated on freenode #coffeescript irc)
Maybe we'll have more luck upstream or downstream: