Opened 3 years ago

Last modified 3 years ago

#12142 new bug

-Wredundant-constraints warns about constraints introduced via type synonyms.

Reported by: scshunt Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.0.1
Keywords: Cc:
Operating System: Linux Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I ran into this when using lens, here's a simplied example:

l :: Getter [a] Int
l = to length

In this case, Getter introduces constraints (Functor f, Contravariant f), but the Functor constraint is not used. This leads to a warning from -Wredundant-constraints:

<interactive>:1:6: warning: [-Wredundant-constraints]
    • Redundant constraint: Functor f
    • In the type signature for:
           l :: (Contravariant f, Functor f) => (Int -> f Int) -> [a] -> f [a]

This shouldn't warn, because the constraints were introduced by type synonym and so may well be opaque to the user.

Change History (2)

comment:1 Changed 3 years ago by simonpj

I can see that's annoying, but it's hard to avoid. And it does tell you something useful, namely that l is less polymorphic, and therefore less usable, than it could be.

It's tantalising -- -Wredundant-constraints really is jolly useful but it is also sometimes annoying.

comment:2 Changed 3 years ago by ekmett

In the interest of not getting drowned in complaints by the users of lens on GHC 8, we'll likely just add the constraint to to and rely on {-# INLINE #-} dropping it out in practice. This is a common enough scenario to warrant us eating the noise on our side.

Of course, you'll get the same sort of thing if you go to declare a non-law abiding traversal as a fold, etc. There i'm afraid the only answer will be to squelch the warning. GHC can't see 'laws'.

Note: See TracTickets for help on using tickets.