[GHC] #11582: Redundant constraints warning complains that (a ~ b) is redundant

#11582: Redundant constraints warning complains that (a ~ b) is redundant -------------------------------------+------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 8.0.1-rc2 (Type checker) | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect Unknown/Multiple | warning at compile-time Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Lemming came up with an interesting example where the redundant constraints warning is arguable a bit too trigger-happy in #10635. Consider, {{{#!hs asTypeOf :: a -> a -> a asTypeOf x _ = x }}} We could equivalently rewrite this with an equality constraint, {{{#!hs 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? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11582 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11582: Redundant constraints warning complains that (a ~ b) is redundant -------------------------------------+------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.1 Component: Compiler (Type | Version: 8.0.1-rc2 checker) | Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => closed * resolution: => invalid Comment: I don't agree. "Redundant" means that if you leave it off the function will still compile. And indeed {{{ asTypeOf1 :: a -> b -> a asTypeOf1 x _ = x }}} is just fine. So I don't know what you mean by saying "the type checker has gleaned something from it". I say it's behaving precisely as advertised, so I'll close as invalid. Re- open if I have misunderstood. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11582#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11582: Redundant constraints warning complains that (a ~ b) is redundant -------------------------------------+------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.1 Component: Compiler (Type | Version: 8.0.1-rc2 checker) | Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Lemming): I thought a bit about it and found that equality constraints and type class constraints actually differ in the following aspect: If you remove a redundant type class constraint from a function type signature then any code depending on that function will continue to be type correct and continue to work as before. In contrast to that, if you remove an equality constraint (or generalize a function like asTypeOf to a more general type), then code might no longer pass the type checker because of ambiguous types. That is, if you eagerly remove all redundant constraints then removed type class constraints will not do any harm but removed equality constraints might do so. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11582#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11582: Redundant constraints warning complains that (a ~ b) is redundant -------------------------------------+------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.1 Component: Compiler (Type | Version: 8.0.1-rc2 checker) | Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): I see. Yes that is true. Sort of. Removing a type class with functional dependencies might have the same effect. Or a type class with a superclass that had functional depencies. Or a type class with a superclass equality like {{{ class (a~b) => C a b where ... }}} And with higher-kinded stuff I don't think we can predict with precision. I suppose you could have `-fwarn-redundant-constraints-for-definition` and `-fwarn-redundant-constraints-for-call-sites`, to say what level of redundancy you wanted to report or at least make best-efforts to report (see above). But I do see what you mean, and it might be good to have such an example in the user manual. Also if you felt like implementing per-signature control that would be cool. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11582#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC