[GHC] #10183: Warning for redundant constraints: interaction with pattern matching

#10183: Warning for redundant constraints: interaction with pattern matching -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Herbert gives this example: {{{ {-# LANGUAGE GADTs, DataKinds, TypeOperators, UnicodeSyntax #-} import GHC.TypeLits data List l t where Nil ∷ List 0 t (:-) ∷ t → List l t → List (l+1) t head' ∷ (1<=l) ⇒ List l t → t head' (x :- _) = x }}} We get the warning {{{ typelits1.hs:9:9: Warning: Redundant constraint: 1 <= l In the type signature for: head' ∷ (1 <= l) ⇒ List l t → t }}} But of course the warning is not redundant if we want to exclude the `(head' Nil)` case. Here's an example that doesn't depend on `TypeLits`: {{{ data T a where TT :: T True TF :: T False f :: T True -> Bool f TT = True g :: (a ~ True) => T a -> Bool g TT = True }}} Here `f` compiles fine, but `g` warns about a redundant constraint! And indeed the evidence for `(a~True)` is not used in the code for `g`. But that evidence is used to prove that the un-matched pattern `(g TF)` is unreachable. I'm not sure how to fix this. Bother. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10183 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10183: Warning for redundant constraints: interaction with pattern matching -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Description changed by simonpj: Old description:
Herbert gives this example: {{{ {-# LANGUAGE GADTs, DataKinds, TypeOperators, UnicodeSyntax #-}
import GHC.TypeLits
data List l t where Nil ∷ List 0 t (:-) ∷ t → List l t → List (l+1) t
head' ∷ (1<=l) ⇒ List l t → t head' (x :- _) = x }}} We get the warning {{{ typelits1.hs:9:9: Warning: Redundant constraint: 1 <= l In the type signature for: head' ∷ (1 <= l) ⇒ List l t → t }}} But of course the warning is not redundant if we want to exclude the `(head' Nil)` case.
Here's an example that doesn't depend on `TypeLits`: {{{ data T a where TT :: T True TF :: T False
f :: T True -> Bool f TT = True
g :: (a ~ True) => T a -> Bool g TT = True }}} Here `f` compiles fine, but `g` warns about a redundant constraint! And indeed the evidence for `(a~True)` is not used in the code for `g`. But that evidence is used to prove that the un-matched pattern `(g TF)` is unreachable.
I'm not sure how to fix this. Bother.
New description: Herbert gives this example: {{{ {-# LANGUAGE GADTs, DataKinds, TypeOperators, UnicodeSyntax #-} import GHC.TypeLits data List l t where Nil ∷ List 0 t (:-) ∷ t → List l t → List (l+1) t head' ∷ (1<=l) ⇒ List l t → t head' (x :- _) = x }}} We get the warning {{{ typelits1.hs:9:9: Warning: Redundant constraint: 1 <= l In the type signature for: head' ∷ (1 <= l) ⇒ List l t → t }}} But of course the warning is not redundant if we want to exclude the `(head' Nil)` case. Here's an example that doesn't depend on `TypeLits`: {{{ data T a where TT :: T True TF :: T False f :: T True -> Bool f TT = True g :: (a ~ True) => T a -> Bool g TT = True }}} Here `f` compiles fine, but `g` warns about a redundant constraint, even though the two types are isomorphic! And indeed the evidence for `(a~True)` is not used in the code for `g`. But that evidence is used to prove that the un-matched pattern `(g TF)` is unreachable. I'm not sure how to fix this. Bother. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10183#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10183: Warning for redundant constraints: interaction with pattern matching -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by goldfire): Does the fancy new pattern-match completeness checker help out here? Can GHC record somehow that a constraint is used when the completeness checker is thinking? In the meantime, does this mean the flag should be excluded from `-Wall` for 7.10? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10183#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10183: Warning for redundant constraints: interaction with pattern matching -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by hvr): * version: 7.8.4 => 7.11 Comment: Afaik this only occurs on GHC HEAD -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10183#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10183: Warning for redundant constraints: interaction with pattern matching -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: redundant- | constraints, GADTs 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 thomie): * keywords: => redundant-constraints, GADTs * failure: None/Unknown => Incorrect warning at compile-time @@ -23,1 +23,1 @@ - Here's an example that doesn't depend on `TypeLits`: + Here's an example that only depends on `GADTs`: @@ -25,0 +25,1 @@ + {-# LANGUAGE GADTs #-} @@ -26,2 +27,2 @@ - TT :: T True - TF :: T False + TT :: T Bool + TF :: T Int @@ -29,1 +30,1 @@ - f :: T True -> Bool + f :: T Bool -> Bool @@ -32,1 +33,1 @@ - g :: (a ~ True) => T a -> Bool + g :: (a ~ Bool) => T a -> Bool @@ -37,1 +38,1 @@ - `(a~True)` is not used in the code for `g`. But that evidence is used to + `(a~Bool)` is not used in the code for `g`. But that evidence is used to New description: Herbert gives this example: {{{ {-# LANGUAGE GADTs, DataKinds, TypeOperators, UnicodeSyntax #-} import GHC.TypeLits data List l t where Nil ∷ List 0 t (:-) ∷ t → List l t → List (l+1) t head' ∷ (1<=l) ⇒ List l t → t head' (x :- _) = x }}} We get the warning {{{ typelits1.hs:9:9: Warning: Redundant constraint: 1 <= l In the type signature for: head' ∷ (1 <= l) ⇒ List l t → t }}} But of course the warning is not redundant if we want to exclude the `(head' Nil)` case. Here's an example that only depends on `GADTs`: {{{ {-# LANGUAGE GADTs #-} data T a where TT :: T Bool TF :: T Int f :: T Bool -> Bool f TT = True g :: (a ~ Bool) => T a -> Bool g TT = True }}} Here `f` compiles fine, but `g` warns about a redundant constraint, even though the two types are isomorphic! And indeed the evidence for `(a~Bool)` is not used in the code for `g`. But that evidence is used to prove that the un-matched pattern `(g TF)` is unreachable. I'm not sure how to fix this. Bother. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10183#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC