Overlapping instances

Johan Nordlander nordland@cse.ogi.edu
Tue, 15 Jan 2002 22:47:05 -0800


On Tuesday, January 15, 2002, at 07:02 PM, Sean Seefried wrote:

> Why is it that this source file
> -- begin code --
> class Numeric a
>     where describe :: a -> String
>
> instance Integral a => Numeric a
>     where describe n = "Integral"
>
> instance Floating a => Numeric a
>     where describe n = "Floating"
> -- end code --
>
> produces  the error message
>
> -- begin code --
> *** This instance   : Numeric a
> *** Overlaps with   : Numeric a
> *** Common instance : Numeric a
> -- end code --
>
> even though I have overlapping instances turned on.  The "+o" option.
> ------------------------------------------------
> Sean Seefried
> School of ITEE
> The University of Queensland
> Ph: 3365 8301
> Mob: 0416 338 636


Hi Sean,

The +o option still only allows overlapping instances where one 
is strictly more general than the other.  And that notion 
doesn't take the contexts of instance declarations into account; 
it only checks whether the instance heads are related by 
substitution.  So even though you might have reason to expect 
the classes Integral and Floating to be disjoint, your instances 
are actually equivalent as far as Hugs sees them.

Also note that there is no general agreement as to what form of 
overlapping instances Haskell should support, let alone whether 
they should be supported at all.

All the best,
Johan