wiki:OverlappingInstances

Version 3 (modified by john@…, 8 years ago) (diff)

--

Overlapping Instances

See ExtensionDescriptionHowto for information on how to write these extension descriptions. Please add any new extensions to the list of HaskellExtensions.

Brief Explanation

overlapping instances allow instances that can unify for the same class and will choose the most specific one available

An alternate to what GHC implements would be to declare whether a class may be overlapping on a class by class basis. perhaps with something like

class overlapping Foo a where
   ...

References

Pros

  • useful on occasion.

Cons

  • including a new module can silently change behavior of a program.
  • makes it very easy for incorrect programs to still typecheck
  • can cause confusing error messages
  • can sometimes be simulated with the extra-method trick used in the Show class of the prelude for showing lists of characters differently than lists of other things.