Opened 5 years ago

Closed 5 years ago

Last modified 13 months 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 (7)

comment:1 Changed 5 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 5 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 5 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 5 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 5 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 4 years ago by thoughtpolice


Milestone renamed

comment:7 Changed 13 months ago by Simon Peyton Jones <simonpj@…>

In 4293a80a/ghc:

Accommodate API change in transSuperClasses

In this patch

    commit 6eabb6ddb7c53784792ee26b1e0657bde7eee7fb
    Author: Simon Peyton Jones <>
    Date:   Tue Dec 15 14:26:13 2015 +0000

    Allow recursive (undecidable) superclasses

I changed (transSuperClasses p) to return only the
superclasses of p, but not p itself. (Previously it always
returned p as well.)

The use of transSuperClasses in TcErrors.warnRedundantConstraints
really needs 'p' in the result -- but I faild to fix this
call site, and instead crippled the test for Trac #10100.

This patch sets things right

* Accomodates the API change
* Re-enables T10100
* And thereby fixes Trac #11474
Note: See TracTickets for help on using tickets.