Closed jakublabenski closed 3 years ago
Hey, thanks for bringing this to my attention. Especially since it's something I should have noticed myself ages ago. Safe to say that exponential complexity is definitely not the intended behaviour.
So I've had a quick look at this and, unfortunately, won't have time to really dig into it until at least the weekend. But the good news is your solution appears to work for Reader. The bad news is other monad have similar constructions and therefore suffer the same complexity problem. And a similar solution doesn't appear to work for those. State in particular has even bigger problems which I'll need to figure out. Hopefully I can find a general solution to fix the problem across the board.
I'll keep you posted. In the meantime, using map and bind directly instead of deferring to then should avoid performance problems in most cases.
So, I've fixed the exponential complexity problem in every monad where it was a problem and also fixed Promise which, it turns out, was really broken. I haven't pushed the code yet because I need to test it thoroughly and clean it up some first which at this point will happen some time tomorrow afternoon my time (EST). New version should be on PyPi around the same time.
Thanks again for bringing this to my attention.
Alright, all fixed. New version is 2.3.5 available here and on PyPi.
I do not know if this is a bug or correct behaviour. This is what I observed:
The result of execution is:
I expected to see this:
Implementation of _bind_or_map is responsible for this:
First _bind is used to compute the result. Bind do mapping and fails on actual binding. Then everything is computed again by _map. This has exponential complexity.
I believe fix could do 'map' then try to 'bind':