Open vigress8 opened 2 months ago
I see many instances of case uncons xs of Just (x, xs) -> ...
, so it seems like a useful addition.
However, I do not see any patterns already defined in mono-traversable. @gregwebs do you have any thoughts on adding pattern exports ghc has had them since 7.8.1 so it seems like a well established feature that does not need CPP for version checking.
@vigress8 can you comment on how to have completeness for the pattern? It seems like this will generate many warnings for incomplete patterns.
hmm, why would this package be the one that defines patterns to export? It doesn't seem related to mono-traversable.
I think that a custom prelude package would define this.
Sorry I wasn't specific, by "this package" I meant classy-prelude
(which is in this repository). Edited now
It doesn't seem related to mono-traversable
It's related because the pattern is meant to be generic over IsSequence
.
sure, makes sense for classy-prelude.
@vigress8 can you comment on how to have completeness for the pattern? It seems like this will generate many warnings for incomplete patterns.
To me the simplest way to achieve completeness seems to be
pattern Empty <- (uncons -> Nothing)
{-# complete Empty, (:::) #-}
Is the name clash acceptable https://hoogle.haskell.org/?hoogle=%3A%3A%3A
Probably better to just use a name and not have a symbol? At least to start?
The specific symbol isn't critically important to me, I just chose it for example's sake
Ok, let's name the pattern Cons
. @vigress8 can you crate a PR?
I'm thinking of something like:
I find myself wanting sequence-polymorphic pattern matching often, personally. It's trivial to define manually but having it in
classy-prelude
would make things simpler. Curious what anyone else thinks