Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's not any better. Ad hoc polymorphism is a defined thing just as overloading is a defined thing (in fact, it's a superset of OO-style "overloading"). When you allow operators to be defined for user-authored datatypes, these are features that you might choose to support for operators, but that doesn't mean that all user-defined operators are inherently using these features.

Concretely, in defining a + operator on your BigInt class that can only accept another BigInt, you haven't overloaded the + operator. It would only be overloading if you defined a second form that accepted some other type of object.



So if I want 3 + myBigInt to work?

(Which I'll note most languages that support operator overloading support)


Yes, that would be actual operator overloading.

Personally, I've always wanted languages to be stricter about that kind of thing. It's not that hard to explicitly express the desired conversions to make the types on both sides of your binary math operators the same and it feels a lot more "controlled" to me to do so.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: