dmwit / universe

Classes for types where we know all the values
BSD 3-Clause "New" or "Revised" License
37 stars 17 forks source link

Orphan instances are evil #16

Closed treeowl closed 8 years ago

treeowl commented 8 years ago

Therefore, I would suggest hiding the (Finite e, Ord e) => Foldable/Traversable (->) e instances behind a newtype.

dmwit commented 8 years ago

Orphan instances can lead to some problems when multiple packages define the same instances.

However, the main existing implementation, namely GHC, will not use any instances in modules it doesn't touch. For that reason, universe has carefully segregated all the orphan instances into their own module (and all these modules are in a completely separate package); this makes it possible for dependencies to choose to avoid universe's instance in favor of a different instance should they need to do that, and moreover forces it to be a conscious choice on the part of the dependency to use these instances.

For executables that depend on universe, this is sufficient. For libraries that depend on universe, a similar discipline is recommended.

I will consider taking a different stance once I have a (potential) user for which this is not possible for some reason.