[GHC] #13021: Inaccessible RHS warning is confusing for users

#13021: Inaccessible RHS warning is confusing for users -------------------------------------+------------------------------------- Reporter: mpickering | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple PatternMatchWarnings | Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- The pattern match checker makes the distinction between redundant matches and matches with an inaccessible right hand side. A pattern with an inaccessible RHS, is a redundant pattern which forces the argument so affects strictness. I think this is confusing for users as most of the time you write programs assuming totality but the error message doesn't make it clear why the two warnings are different. I think that instead they should both be called redundant but a note added to the inaccessible case explaining that removing it could affect strictness. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13021 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13021: Inaccessible RHS warning is confusing for users -------------------------------------+------------------------------------- Reporter: mpickering | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | PatternMatchWarnings 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 gkaracha): Even though I understand that the message can be confusing, I disagree with calling it in any way "redundant". Pattern matching is side-effectful in a lazy language and in fact we often use it just to force evaluation, so I would not consider it a minor thing. Before GHC 8, both redundant and with-inaccessible-rhs clauses where called "overlapping" which may be more appropriate. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13021#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13021: Inaccessible RHS warning is confusing for users -------------------------------------+------------------------------------- Reporter: mpickering | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | PatternMatchWarnings 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 goldfire): I'm with @gkaracha here in that I would want these messages to remain separate. On the other hand, I'd love it if we could put URLs in error messages (perhaps enabled by a `-fprint-info-links` flag or some such) so that confused users can get more information. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13021#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13021: Inaccessible RHS warning is confusing for users -------------------------------------+------------------------------------- Reporter: mpickering | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | PatternMatchWarnings 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 mpickering): How is a user expected to react to this warning? It seems that they can't act on it without changing the semantics of their program. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13021#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13021: Inaccessible RHS warning is confusing for users -------------------------------------+------------------------------------- Reporter: mpickering | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | PatternMatchWarnings 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 goldfire): Do you have an example that we could contemplate? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13021#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13021: Inaccessible RHS warning is confusing for users -------------------------------------+------------------------------------- Reporter: mpickering | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | PatternMatchWarnings 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 mpickering): It is easy to trigger cases like this with `COMPLETE` signatures as they are currently designed. For example, {{{ data T = A | B | C {-# COMPLETE B #-} foo :: T -> () foo A = () foo B = () }}} Then the first match is reported as having an inaccessible RHS. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13021#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13021: Inaccessible RHS warning is confusing for users -------------------------------------+------------------------------------- Reporter: mpickering | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | PatternMatchWarnings 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 gkaracha): Yes, it makes sense in these cases, since they are actually semantically wrong. But is there an example for a meaningful `COMPLETE` set? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13021#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13021: Inaccessible RHS warning is confusing for users -------------------------------------+------------------------------------- Reporter: mpickering | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | PatternMatchWarnings 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 rwbarton): I don't understand what is going on in this example. Suppose `B` was a pattern synonym and we couldn't see its definition. Then the `COMPLETE` pragma could be semantically correct. But if we match `A` before `B` then the match isn't redundant, the behavior of the function could be different in the `A` case. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13021#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13021: Inaccessible RHS warning is confusing for users -------------------------------------+------------------------------------- Reporter: mpickering | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | PatternMatchWarnings 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 mpickering): The `COMPLETE` pragma is an assertion that writing a function which matches on each of the constructors in the set is total. In this example, for this to be true, there can be no `A` values as if there were, no function just matching on `B` would be total. Thus, the warning about the inaccessible RHS is correct wrt the assertion made by the programmer. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13021#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13021: Inaccessible RHS warning is confusing for users -------------------------------------+------------------------------------- Reporter: mpickering | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | PatternMatchWarnings 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 rwbarton): My confusion here is at a very basic level. `_` is a pattern such that any set of pattern matches which includes `_` is total. Yet in a function like {{{ f :: Maybe a -> Int f Nothing = 0 f _ = 1 }}} the first equation is not redundant in a practical sense, even though the pattern match would still be total without it. There's more to life than totality of pattern matches. I thought that a `{-# COMPLETE p1, ..., pn #-}` pragma was just supposed to mean that a function that matches all of the `pi` should be regarded as total. It doesn't make any sense to me for the compiler to use this knowledge plus the definitions of the `pi` to make any conclusions about whether other values are possible or not. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13021#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13021: Inaccessible RHS warning is confusing for users -------------------------------------+------------------------------------- Reporter: mpickering | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | PatternMatchWarnings 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 goldfire): I'm with @rwbarton. The fact that `B` is `COMPLETE` in comment:5 does not make the first match redundant or inaccessible. His suggestion to consider `pattern B <- _` (which is indeed a complete pattern) is instructive. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13021#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC