reazen / relude

FP-inspired prelude/standard library for ReasonML projects
https://reazen.github.io/relude
MIT License
267 stars 41 forks source link

Rewrite Flatten to be stack safe #246

Closed RawToast closed 4 years ago

RawToast commented 4 years ago

The current Flatten implementation for lists (AFAIK) is not stack-safe. I've experienced stack issues flattening very large datasets -- where I had to write my own flatten method instead. I believe this is because it uses List.concat or @ under the hood, which is not safe, but struggle to read the Bs-Abstract/Belt code.

Methods like this should be rewritten to be safe. In the Scala standard library, this is often done using mutation-based implementations but if we can use tail recursive methods then that's good too!

On the back of this, it might be worth creating new methods for many list functions (e.g. concat) that are stack safe.

This might be fixed by #166 if that's the case, you can close this issue 😸

andywhite37 commented 4 years ago

This is a legit issue - there are a number of things that aren't stack safe in the library. MonadRec could potentially solve some of the higher-level things, but we'd be happy to accept one-off PRs that fix individual functions like flatten with more optimized or tail-recursive implementations.

We might be able to address some of these over time, but I've been busy with other things the past few months, so I haven't had a ton of time to dedicate to this.

andywhite37 commented 4 years ago

I'll close this in favor of #247, since there is a more comprehensive list there