New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More NonEmpty variants of inits & tails #67
Comments
+1. This proposal is consistent with the already existing |
+1 |
1 similar comment
+1 |
I am aware that as the issue creator I am responsible for making this happen, and I do intend to make a PR at some point, although I’m not sure exactly when I’ll get around to it. |
@hdgarrood yes, please raise an MR, so that we can vote on a specific implementation. |
@hdgarrood just a gentle reminder to raise an MR, so that we can proceed forward. |
This just landed: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/8880 so I guess this issue can be closed? |
No, Ben mistakenly went ahead with a merge without CLC approval. If the proposal happens to be declined, we'll revert. Dear CLC members, let's vote on https://gitlab.haskell.org/ghc/ghc/-/merge_requests/8880, adding +1 from me, seems pretty uncontroversial. |
+1 |
+1, thank you @hdgarrood ! |
+1 less work for ben, more things for us |
Awesome, 4 votes are enough to approve, thanks all. |
I'm trying to summarise the state of this proposal as part of my volunteering effort to track the progress of all
Please, let me know if you find any mistakes 🙂 |
At the moment
Data.List.NonEmpty
has the following variants ofinits
andtails
:where the input list may be empty, but the output list is guaranteed to contain at least one element (namely, the input list). Note that
inits
andtails
will always both include the empty list at the start and end of their return values, respectively:While it seems reasonable to consider the empty list to be a prefix and a suffix of every list and therefore to include it in the return value, I'd argue it's not always an interesting or useful element. Sometimes, I want to use
inits
ortails
on a list which I already know to be nonempty, and I only care about the nonempty prefixes/suffixes. To that end, I think it might be useful to have variants like this:such that (modulo types), we'd have:
A concrete example where this would be useful is in the PureScript compiler: https://github.com/purescript/purescript/blob/8181c4fee34fdfa576ad7029ec2303f71020e1b6/src/Language/PureScript/TypeChecker/Entailment.hs#L261-L273
At the moment, we have code that uses regular lists, and does
where
chain
is a regular list which is known to be nonempty, and where we have an unsafe incomplete pattern match which doesn't blow up at runtime because of theinit
(which removes the empty list at the end oftails
). Withtails1
, we could changechain
to be aNonEmpty
, and change the above line toand have all of the non-emptiness facts that we are relying on tracked safely in the types.
The text was updated successfully, but these errors were encountered: