Ticket #565 (closed bug: invalid)

Opened 11 years ago

Last modified 2 years ago

overlapping instances & fundeps broken

Reported by: ashley-y Owned by: simonpj
Priority: low Milestone: _|_
Component: Compiler (Type checker) Version: 5.0
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description (last modified by igloo) (diff)

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.

Change History

Changed 5 years ago by igloo

  • difficulty set to Unknown
  • milestone set to _|_
  • os set to Unknown
  • architecture set to Unknown
  • description modified (diff)

Changed 3 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 3 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple

Changed 3 years ago by igloo

  • owner nobody deleted
  • status changed from assigned to new

Changed 2 years ago by ganesh

  • failure set to None/Unknown

The problem with all these examples is that someone (in another module) add instance Num Bool, and now the instances really do overlap, and the fundep is violated.

So I think this bug should be closed as invalid.

Changed 2 years ago by igloo

  • owner set to simonpj

I agree; Simon, can you confirm and close it, please?

Changed 2 years ago by simonpj

  • status changed from new to closed
  • resolution changed from None to invalid

I agree. And in any case we want to encourage people to move towards type functions, partly because questions like this are pretty tricky.

Simon

Note: See TracTickets for help on using tickets.