[GHC] #9182: Empty case analysis for function clauses

#9182: Empty case analysis for function clauses ------------------------------------+------------------------------------- Reporter: dfranke | Owner: Type: feature request | Status: new Priority: low | Milestone: Component: Compiler | Version: 7.8.2 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- Thanks to `-XEmptyCase`, the following is legal: {{{ module Empty where data Empty empty :: Empty -> a empty x = case x of { } }}} However, if I leave off the last line, GHC will complain that `The type signature for ‘empty’ lacks an accompanying binding`. I think this program should be accepted. It isn't that I'm not giving a definition for `empty`; it's that I'm defining it to be a function with no accompanying equations, as could be represented in Template Haskell by $(return [FunD (mkName "empty") []]) Currently, this too is rejected, with GHC complaining `Function binding for ‘empty’ has no equations`. I think this should be legal, with an empty list of clauses in a function definition being treated the same way as an empty list of matches in a case expression. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9182 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9182: Empty case analysis for function clauses -------------------------------------+------------------------------------ Reporter: dfranke | Owner: Type: feature request | Status: new Priority: low | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Description changed by dfranke: Old description:
Thanks to `-XEmptyCase`, the following is legal:
{{{ module Empty where
data Empty
empty :: Empty -> a empty x = case x of { } }}}
However, if I leave off the last line, GHC will complain that `The type signature for ‘empty’ lacks an accompanying binding`.
I think this program should be accepted. It isn't that I'm not giving a definition for `empty`; it's that I'm defining it to be a function with no accompanying equations, as could be represented in Template Haskell by
$(return [FunD (mkName "empty") []])
Currently, this too is rejected, with GHC complaining `Function binding for ‘empty’ has no equations`. I think this should be legal, with an empty list of clauses in a function definition being treated the same way as an empty list of matches in a case expression.
New description: Thanks to `-XEmptyCase`, the following is legal: {{{ module Empty where data Empty empty :: Empty -> a empty x = case x of { } }}} However, if I leave off the last line, GHC will complain that `The type signature for ‘empty’ lacks an accompanying binding`. I think this program should be accepted. It isn't that I'm not giving a definition for `empty`; it's that I'm defining it to be a function with no accompanying equations, as could be represented in Template Haskell by {{{$(return [FunD (mkName "empty") []])}}} Currently, this too is rejected, with GHC complaining `Function binding for ‘empty’ has no equations`. I think this should be legal, with an empty list of clauses in a function definition being treated the same way as an empty list of matches in a case expression. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9182#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9182: Empty case analysis for function clauses -------------------------------------+------------------------------------ Reporter: dfranke | Owner: Type: feature request | Status: new Priority: low | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by Fuuzetsu): But empty does have one case, where `x = undefined`. You can't pattern match on it but it's there. I imagine that this is in attempt to simulate : ∀ α. ⊥ → α where we use the impossible pattern in empty but that's just not the case in Haskell and even in Agda &c the binding is necessary anyway. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9182#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9182: Empty case analysis for function clauses -------------------------------------+------------------------------------ Reporter: dfranke | Owner: Type: feature request | Status: new Priority: low | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by nomeata): Tricky. I believe the `The type signature for ‘empty’ lacks an accompanying binding.` message is emitted early, possibly during renaming, when there is no way to know that `Empty` is empty. Or are you suggesting to disable this error message completely when `EmptyCase` is active? And what’s wrong with writing `empty x = case x of { }`? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9182#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9182: Empty case analysis for function clauses -------------------------------------+------------------------------------ Reporter: dfranke | Owner: Type: feature request | Status: new Priority: low | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by dfranke): Yes, with EmptyCase active I would take any type declaration without an accompanying binding as denoting an empty definition, and then issue a warning about an inexhaustive pattern match later on when appropriate. Having to write the empty case expression doesn't prevent you from doing anything. It just adds clutter, and allowing empty case analysis in some syntactic contexts but not others is an unnecessary inconsistency. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9182#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9182: Empty case analysis for function clauses -------------------------------------+------------------------------------- Reporter: dfranke | Owner: Type: feature request | Status: new Priority: low | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11390 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * related: => #11390 Comment: A somewhat similar discussion took place in #11390. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9182#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC