Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,829
    • Issues 4,829
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 444
    • Merge requests 444
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #565

Closed
Open
Created Jul 15, 2001 by ashley-y@trac-ashley-y

overlapping instances & fundeps broken

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.
Edited Mar 09, 2019 by Ian Lynagh <igloo@earth.li>
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking