Skip to content

Redundant constraints warning complains that (a ~ b) is redundant

Lemming came up with an interesting example where the redundant constraints warning is arguable a bit too trigger-happy in #10635 (closed). Consider,

asTypeOf :: a -> a -> a
asTypeOf x _ = x

We could equivalently rewrite this with an equality constraint,

asTypeOf1 :: (a ~ b) => a -> b -> a
asTypeOf1 x _ = x

If compiled with GHC 8.0 with -Wredundant-constraints we see a warning,

hi.hs:4:1: warning:
    • Redundant constraint: a ~ b
    • In the type signature for:
           asTypeOf1 :: (a ~ b) => a -> b -> a

But is this really unused? We may not have referenced the constraint in the RHS, but surely the typechecker has gleaned something from it.

Perhaps we should simply ignore equality constraints when generating redundant constraint warnings?

Trac metadata
Trac field Value
Version 8.0.1-rc2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC Lemming
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information