Skip to content
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

List_nonempty module #1057

Open
rixed opened this issue Oct 30, 2021 · 6 comments
Open

List_nonempty module #1057

rixed opened this issue Oct 30, 2021 · 6 comments

Comments

@rixed
Copy link
Contributor

rixed commented Oct 30, 2021

from https://discuss.ocaml.org/t/share-your-crazy-ocaml-code-snippet/8116/38 :

Sometimes, I think a feature-full List_nonempty module would be cool in batteries, or as a standalone library.
It should support most BatList operations (and only have tail rec. code).

I too think it would be useful.

@UnixJunkie
Copy link
Member

Apparently there is one in Core_kernel: https://github.com/janestreet/core_kernel/tree/master/nonempty_list
We could import part of it and use the interface we want (though this implementation file would be using the MIT license then).

@UnixJunkie
Copy link
Member

One way to start resolving this issue would be to agree on the interface, which I believe should be a subset of batList.
Once the interface is agreed upon, we could implement all the functions.

@rixed
Copy link
Contributor Author

rixed commented Jan 19, 2022

Indeed, I see no reason why we should not aim for a subset of BatList as far as API goes.
What seams less obvious to me is what should be the actual encoding. Should a non empty list be an item + a normal list (as in Core's implementation it seems), which has the advantage of offering a free conversion from/to lists ; or should a list be either the last item or an item + a non empty list, which seems marginally cleaner and makes the definition "safer" (it can then be public and allow users to pattern match directly).

@UnixJunkie
Copy link
Member

UnixJunkie commented Jan 20, 2022 via email

@rixed
Copy link
Contributor Author

rixed commented Jan 20, 2022

This makes a lot of sense.

@UnixJunkie
Copy link
Member

I have started some work here: https://github.com/UnixJunkie/batteries-included/tree/non_empty_list
The idea is to uncomment little by little the bottom of the file, implementing things along the way;
keeping BatList's unit tests as much as possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants