-
Notifications
You must be signed in to change notification settings - Fork 609
feat: binary recursive implementation of List.mapA #3877
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
base: master
Are you sure you want to change the base?
Conversation
Mathlib CI status (docs):
|
!bench |
Here are the benchmark results for commit f405eb4. |
(note: the benchmark is useless because |
Could you add a doc-string explaining at least that the complicated implementation is for performance, and ideally explaining why tail-recursiveness is impossible and that this is "the next best thing"? |
Inspired by #3867 (comment) . After playing with this function a bit more, I was able to confirm that it's not really possible to implement it tail recursively in most monads (note that tail-recursiveness depends on the monad itself), because
seq
is not tail recursive in most monads and you have to stack up at leastn-1
of them to reduce a list of lengthn
. However, we can do the next best thing which is to use a balanced tree ofseq
applications. I have confirmed that this will evaluatewithout stack overflow, unlike the original implementation, but it still deserves a
!bench
because the binary reduction has overhead and it may be worthwhile to switch over to naive recursion below some threshold.