|
|
|
|
|
by snprbob86
4808 days ago
|
|
At least in Clojure, it's considered bad form to extend your own protocols (aka instance type classes) to types you don't own. Isn't that also true of Haskell? Haskell's type classes, unlike ML functors (I think), are "coherent", which means that you can't have scoped or multiple instances for the same type, lest you risk breaking the type system. With that in mind, extending Maybe to Num would mean a reduction the number of type errors caught in other code that uses Maybe and Num near each other. |
|
http://stackoverflow.com/questions/3079537/orphaned-instance...
There are occasions where it can be useful to have a module export an orphan instance for compatibility before it makes it into the more appropriate spot in the standard libs.
And you're right you can't have multiple instances for the same type; a newtype wrapper is required.