feat: binary recursive implementation of List.mapA - #3877
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"? |
what are these monads? maybe for these monads possible to create class CanImplementTailRecursivenessFor m where
proof_x : ...and then write in docstring for and if monad has |
|
This hasn't been touched in over a year, and has a merge conflict. I'm closing now; please re-open if you think appropriate. |
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
seqis not tail recursive in most monads and you have to stack up at leastn-1of them to reduce a list of lengthn. However, we can do the next best thing which is to use a balanced tree ofseqapplications. I have confirmed that this will evaluatewithout stack overflow, unlike the original implementation, but it still deserves a
!benchbecause the binary reduction has overhead and it may be worthwhile to switch over to naive recursion below some threshold.