[Haskell-cafe] Overlapping/Incoherent instances

wren ng thornton wren at freegeek.org
Sun Oct 12 17:58:35 EDT 2008

Don Stewart wrote:
> A quick, ad hoc search reveals, for the "OverlappingInstances" flag,
> (some of these may only mention it in docs or in test suites),
> [...]
>     logfloat-0.9.1

Ah yes, logfloat is using them too, for some of the auxiliary stuff.

* PartialOrd was designed to fix certain brokennesses of the Prelude's 
Ord. Naturally any totally ordered type is also partially ordered, so 
we'd like to have |Ord a => PartialOrd a| with the obvious 
implementation[1]. However the Ord instances for Float and Double are 
lies because of NaN values.

I derive the |Ord a => PartialOrd a| instance because I'm a bad little 
Haskeller who wanted to make things easier for users of the library. 
This usage of OverlappingInstances seems fairly common when people 
introduce new classes to the hierarchy, particularly when they are 
relaxing requirements of the official classes. That is, there are some 
default implementations we'd like to give but cannot for some reason, 
and OverlappingInstances allows us to give them.

* Transfinite uses it for similar reasons to fix brokenness of the 
realToFrac function when converting transfinite values into the Rational 
type. That is, |Transfinite a => RealToFrac a Rational| is not 
inhabitable for any |a| since Rational cannot absorb transfinite values.

Both of these seem like good changes for haskell' in order to correct 
the behavior of Float and Double (and because there are many more 
partially ordered types than totally ordered ones). Alas I've not had a 
chance to file the suggestions.

[1] Given that Ord is more popular. Conversely, if the Prelude is 
changed, we may wish to require PartialOrd for all Ord instances, and 
thing give Ord a default implementation that removes the Just from the 
PartialOrd versions.

Live well,

More information about the Haskell-Cafe mailing list