Opened 3 years ago

Closed 3 years ago

Last modified 2 years ago

#10100 closed bug (fixed)

Bogus "redundant constraint" warning with functional dependencies

Reported by: jstolarek Owned by: simonpj
Priority: normal Milestone: 8.0.1
Component: Compiler Version: 7.11
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: typecheck/should_compile/T10100
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Compiling this code with GHC HEAD:

{-# LANGUAGE MultiParamTypeClasses  #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances      #-}
{-# LANGUAGE UndecidableInstances   #-}

module T10100 where

data Zero
data Succ a

class Add a b ab | a b -> ab, a ab -> b
instance Add Zero b b
instance (Add a b ab) => Add (Succ a) b (Succ ab)

Gives a bogus warning about redundant constraint:

Redundant constraint: Add a b ab
In the instance declaration for ‘Add (Succ a) b (Succ ab)’

Change History (6)

comment:1 Changed 3 years ago by jstolarek

Milestone: 7.10.1
Owner: set to simonpj

I believe that:

  • this should be fixed in GHC 7.10. I'm setting milestone to 7.10.1 but if there's no time to fix it for 7.10.1 release then please punt it to 7.10.2
  • Simon implemented this check, so I'm setting owner to simonpj. Simon, I hope this is correct but if not then please unassign yourself.

comment:2 Changed 3 years ago by simonpj

Humph. In one sense the constraint IS redundant: you simply don't need the evidence (dictionary) for Add a b ab to create evidence for Add (Succ a) b (Succ ab).

But you want nevertheless to allow this (or not warn about it), because you want to prove things like Add (Succ Zero) beta (Succ Zero), by unifying beta := Zero. That won't happen unless you generate the constraint Add Zero beta Zero.

Hmm, well I suppose we should suppress the warnings where there are functional dependencies. I'll work on it.


comment:3 Changed 3 years ago by Simon Peyton Jones <simonpj@…>

In 10fab31211961c9200d230556ec7742e07a6c831/ghc:

Don't report instance constraints with fundeps as redundant

More subtlety due to functional dependencies.
Note [Redundant constraints in instance decls] in TcErrors.

Fixes Trac #10100.

comment:4 Changed 3 years ago by simonpj

Status: newmerge
Test Case: typecheck/should_compile/T10100

I've fixed this and added the example as a test.

Merge to 7.10


comment:5 Changed 3 years ago by thoughtpolice

Resolution: fixed
Status: mergeclosed

Actually, after spending a second trying to merge this, I realized something very silly - -fwarn-redundant-constraints isn't in GHC 7.10 anyway! So, this can be closed I think.

comment:6 Changed 2 years ago by thoughtpolice


Milestone renamed

Note: See TracTickets for help on using tickets.