Re: [Haskell-cafe] Wincomplete-uni-patterns and bidirectional patterns

On Mon, Jan 15, 2024 at 12:00:16PM +0100, Olaf Klinke wrote:
How can I teach GHC 9 that the pattern is indeed exhaustive?
Have you tried COMPLETE pragmas?
https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/pragmas.html#complet...
Tom
Huh, of course that works. Thanks. It never occurred to me to even consider the existence of manual completeness annotation, since completeness checks work so reliably for ordinary constructors. But maybe my types weren't esoteric enough so far. Are there pattern-free cases where the GHC completeness checker is wrong? Of what computational class is the problem? Can I simulate a Turing machine by checking completeness in the presence of patterns? Olaf

On Mon, Jan 15, 2024 at 08:56:33PM +0100, Olaf Klinke wrote:
On Mon, Jan 15, 2024 at 12:00:16PM +0100, Olaf Klinke wrote:
How can I teach GHC 9 that the pattern is indeed exhaustive?
Have you tried COMPLETE pragmas?
https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/pragmas.html#complet...
Huh, of course that works. Thanks.
You're welcome.
It never occurred to me to even consider the existence of manual completeness annotation, since completeness checks work so reliably for ordinary constructors. But maybe my types weren't esoteric enough so far. Are there pattern-free cases where the GHC completeness checker is wrong? Of what computational class is the problem? Can I simulate a Turing machine by checking completeness in the presence of patterns?
I think the completeness checker works fine in all pattern-synonym-free cases, i.e. when you're using only real constructors. I don't actually understand why completeness annotations are needed for pattern synonyms. Tom

I think the completeness checker works fine in all pattern-synonym-free cases, i.e. when you're using only real constructors. I don't actually understand why completeness annotations are needed for pattern synonyms.
I remember reading somewhere, but I can't find it now, that GHC's coverage checker does not look inside pattern synonym definitions at all, and this is by design: namely to ensure abstraction boundaries. Looking inside the definition would mean that type checking behaviour (in a way -- if you count coverage checks as "type checking") of user code is influenced by invisible implementation details of the "constructors" they're using. My own thoughts on this: if GHC would look inside pattern synonym definitions, then it would be hard to ensure that GHC thinks that certain things are _not_ complete even if technically they are. For example, if you have a data type with, say, 3 constructors, but you hide some of those (don't export them) and use pattern synonyms to make it look like 4 constructors, then you might want GHC's coverage checker to consider that a data type with 4 constructors, not one with 3. COMPLETE pragmas add "positive" information -- "this set is complete, in addition to whatever other complete sets GHC might already know" -- and there is no way to _subtract_ complete sets from GHC's knowledge base. This is mostly me theorising, but perhaps it helps. - other Tom
participants (3)
-
Olaf Klinke
-
Tom Ellis
-
Tom Smeding