[GHC] #15459: Wredundant-constraints does not work when constraint synonym is used

#15459: Wredundant-constraints does not work when constraint synonym is used -------------------------------------+------------------------------------- Reporter: flip101 | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- {{{ {-# LANGUAGE ConstraintKinds #-} {-# OPTIONS_GHC -Wredundant-constraints #-} module Main where import Data.List main :: IO () main = return () withWarning :: (Show a, Ord a) => [a] -> [a] withWarning = sort type ConstraintSynonym a = (Show a, Ord a) withoutWarning :: ConstraintSynonym a => [a] -> [a] withoutWarning = sort }}} {{{ Main.hs:12:1: warning: [-Wredundant-constraints] • Redundant constraint: Show a • In the type signature for: withWarning :: forall a. (Show a, Ord a) => [a] -> [a] | 14 | withWarning :: (Show a, Ord a) => [a] -> [a] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ }}} The withoutWarning function does not need the (Show a) constraint but there is no warning for it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15459 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15459: Wredundant-constraints does not work when constraint synonym is used -------------------------------------+------------------------------------- Reporter: flip101 | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Yes, this is a little awkward * `withWarning` has two separate constraints; its type is really curried, like this: {{{ withWarning :: Show a => Ord a => [a] -> [a] }}} * `withoutWarnig` only has one constraint, a tuple. It is uncurried. This is so even though it's only a synonym, so that if you ask say `:t withoutWarning` it'll display the type with the synonym. But the result is that the compound constraint for `withoutWarning` is in fact used (by `sort`). I'm sure it'd be possible to fix this, but there's a bit of a grey zone. What about {{{ type family F a :: Constraint type instance F [a] = (Show a, Ord a) foo :: F [a] => [a] -> [a] }}} Do you expect a warning for that? A type system is a degenerate form of this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15459#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15459: Wredundant-constraints does not work when constraint synonym is used -------------------------------------+------------------------------------- Reporter: flip101 | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by flip101): Simon, i don't know about type families. I tried reading about them at https://wiki.haskell.org/GHC/Type_families but even so i don't feel i have enough experience with them to give a useful response to your question. It's also more confusing for me because in your example foo doesn't have an implementation. With `withoutWarning = sort` it was clear to me that sort requires Ord but not Show. I will make a guess here and say "yes i expect a warning for that". When the instance `F [a]` is used in used in the function `foo` it can be deduced that this is the is the active instance which is used in the function foo. If foo is implemented as `foo = sort` then (`Show a`) is also redundant in the instance of the .. constraint type family ? My guess can be non-sense .. please refer to the first paragraph :P -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15459#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC