Opened 4 years ago

Last modified 3 years ago

#11099 new bug

Incorrect warning about redundant constraints

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

Description

The following program results in an incorrect warning about a redundant constraint:

{-# LANGUAGE TypeFamilies #-}

type family SomeFun a 

f :: (SomeFun i ~ [a], Read a) => proxy i -> a
f _ = read "HELLO"

This is the warning:

Redundant constraint: SomeFun i ~ [a]
    In the type signature for:
         f :: (SomeFun i ~ [a], Read a) => proxy i -> a

I tried it on GHC version 7.11.20151029

Change History (6)

comment:1 Changed 4 years ago by rwbarton

I think redundant here means basically: the definition of f would be accepted without the constraint. It doesn't mean that the type of f would be the same if you removed the constraint. The idea is to catch constraints that aren't actually used in the function, so that you could make the type of the function more general.

In that case the constraint really is redundant, right?

comment:2 Changed 4 years ago by diatchki

I don't see how it is redundant---without that constraint I couldn't write the required type for the function: notice that the constraint is used to compute the type of the output from the type of the input.

If I was to remove the constraint, then the connection between the input and output type is lost, and so uses of this function would become ambiguous in some contexts.

In other situations (e.g., the function get here) this would be not just ambiguous but also plain wrong.

comment:3 Changed 4 years ago by rwbarton

I understand why you don't want the warning, I'm just saying that the warning is working as designed. Perhaps it would be possible to divine the programmer's intent in this case and suppress the warning automatically.

comment:4 Changed 4 years ago by simonpj

  • You want to give a signature to the function that is less polymorphic than its most general type.
  • You may have legitimate reasons for wanting to do so.
  • Insofar as you do so by adding a constraint that isn't used, GHC may complain if you use -fwarn-redundant-constraints.

Hmm. We'd really like a per-function way of suppressing the warning.

comment:5 Changed 4 years ago by thomie

Type of failure: None/UnknownIncorrect warning at compile-time

comment:6 Changed 3 years ago by Iceland_jack

Keywords: CustomTypeErrors added
Note: See TracTickets for help on using tickets.