[ ghc-Bugs-441389 ] overlapping instances & fundeps broken

noreply@sourceforge.net noreply@sourceforge.net
Thu, 03 Jan 2002 05:39:18 -0800


Bugs item #441389, was opened at 2001-07-14 22:03
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=108032&aid=441389&group_id=8032

Category: Compiler (Type checker)
Group: 5.00
Status: Open
Resolution: None
>Priority: 3
Submitted By: Ashley Yakeley (ashley-y)
Assigned to: Nobody/Anonymous (nobody)
Summary: overlapping instances & fundeps broken

Initial Comment:
Consider this:

--
class X a
instance X Bool
instance (Num a) => X a
--

For as long as "instance Num Bool" is not declared, the two instances do 
not de facto overlap. But that's not immediately obvious to GHC, so it will 
complain, at least by default. But I can stop it complaining by passing 
-fallow-overlapping-instances, which I interpret as asking GHC to trust me 
that instances don't actually overlap.

But consider this, with an added dependent argument:

--
class X a b | a -> b
instance X Bool Bool
instance (Num a) => X a Char
--

Now GHC will complain even with -fallow-overlapping-instances. I believe 
this is inappropriate.

So why have the fundep? Well, GHC can still make use of it, and it can still 
calculate the dependent type:

--
class X a b | a -> b where
  {
  foo :: a -> b;
  };

instance X Bool Bool where
  {
  foo a = a;
  };

instance (Num a) => X a Char where
  {
  foo a = 'N';
  }

test = foo True;
--

Without the fundep, GHC cannot calculate 'foo True', since 'instance X Bool 
Bool' is not general enough. This is correct. But with the fundep, GHC will 
complain that it can't prove that the two instances don't conflict for the 
fundep, even with -fallow-overlapping-instances.

I submit that GHC with -fallow-overlapping-instances should not complain 
in this case.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=108032&aid=441389&group_id=8032