overlapping instances and constraints

Ashley Yakeley ashley at semantic.org
Wed Mar 1 21:51:33 EST 2006

Ben Rudiak-Gould wrote:

> I think all of these problems would go away if overlap was permitted 
> within a module but forbidden across modules. Are there uses of 
> overlapping instances for which this isn't flexible enough?

I dislike this on principle. I like the idea that modules can be 
refactored easily.

But I'm not a big fan of overlapping instances anyway, and don't turn on 
the option. This makes it easier to reason about instances, as they 
always apply to their complete domains.

I'm much more interested in allowing non-overlapping instances such as:

   class C a
   instance C Bool
   instance (Num a) => C a

However, I'm aware this is hard for the type-checker. In general, I 
think there's a consensus on what the type-checker should allow in a 
perfect world (assuming one has made a decision on whether to allow 
overlapping instances etc.). It seems the problem is how much of 
perfection can be implemented. It might be worth collecting examples of 
"things that don't compile but should" on a HaskellWiki page.

More information about the Haskell-prime mailing list