Hacker News new | past | comments | ask | show | jobs | submit login

Is it really less confusing that + for numbers has another meaning that + for a newtype that implements Num?



I think so, since you can also count on that type to implement the other required methods of Num.


Right, the fact that functions and operators must be part of a typeclass to be overloaded makes a huge difference. Sure, you can define your Num instance however you want—but that doesn't change the fact that by providing a Num instance you're asserting that the type is "number-like". The typeclass also enforces certain restrictions, such as the fact that the arguments and return value of (+) must all be the same type, which helps curtail the more egregious abuses like the repurposing of the C++ bit-shift operator for stream I/O. And since the set of possible operators is so much larger (almost any sequence of Unicode symbols) there isn't a great deal of pressure to abuse the existing notation. In C++ you can only override the limited set of built-in operators, even if the concept you're trying to express isn't closely related to any of them.

It helps that Haskell operators are namespaced just like functions, so you can choose which operators to bring into scope from other modules.


There is no way to enforce that + actually implements the concept of adding two values.


With dependent types you can. I'm not aware of whether that proof is possible in Haskell, however.

Besides, that's not what I was saying. What I was saying it that + in Haskell means more than an overloaded operator. It means the type has access to additional methods. This gives you more information.


In that case you get the same information on any usable C++ IDE.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: