-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add ListBuilder API #926
Comments
I personally think this would be helpful, but we'd need to consider this vs. taking a dependency on System.Collection.Immutable and offering a |
I think when implementing the ListBuilder the ImmutableCollections tools could easily be implemented as extensions using it. However I don't know how you feel about adding a reference to System.Collections.Immutable to FSharp.Core in general, so if this will be done anyways using its builders would certainly be a way to go... |
I would love to add that dependency. But @dsyme and @KevinRansom have expressed a distaste for additional dependencies in the past. |
A possibility is that we have a second library TBH we could even split up FSharp.Core and and use type forwarders, e.g.
but it's tiresome and expensive to get that right |
I think the ListBuilder should really go into FSharp.Core nonetheless and there it can also be implemented without any reflection things afaik. |
FWIW, I have written an implementation of It does not use reflection but it is kind of brittle because it depends on the list type's internal structure. Code that is using it should add tests to validate that its behavior does not change in later versions of |
See https://github.com/fsharp/fslang-design/blob/main/FSharp-6.0/FS-1099-list-collector.md for fast list and array builders in F# compiler proper |
Completed in F# 6.0 |
ListBuilder
I propose we add a new type to FSharp.Core that allows to build lists in a forward-manner (allowing for tail-recursive implementations).
This way we could expose a safe-way of building lists outside FSharp.Core.
I implemented the
ListBuilder
in my own project usingReflection.Emit
but in FSharp.Core this could be done safely and I think many applications could benefit from this.The existing way of approaching this problem in F# is building lists backwards and then reversing them which is costly and performs lots of allocations. Another way of doing that is by using a non-tail recursion but this tends to crash on large lists.
Pros and Cons
The advantages of making this adjustment to F# are that users could write their own efficient list-combinators that are tail-recursive.
Extra information
Estimated cost (XS, S, M, L, XL, XXL):
XS
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
The text was updated successfully, but these errors were encountered: