3 ms·
> Most functional languages have immutable persistent data structures that don't require a linear copy and are fairly efficient. This is true, but unfortunatel
by repsilat 7y ago
> Most functional languages have immutable persistent data structures that don't require a linear copy and are fairly efficient.
This is true, but unfortunately those libraries/languages don't make use of that tree structure for "partial memoization" of derived data. They very well could, but they don't -- even when you use Immutable.js in a Redux app, and you use Reselect, your selectors will take linear time when you mutate one element in an object/array instead of taking constant- or log-time.
- fyp 7y agoYea that's a good point. This matters when your derived data takes linear time to recompute. There are still techniques to make this work (but not automatically afaik). For example it's easy to make them efficient again if your computation is just an associative fold or reversible fold: https://sci-hub.tw/https://link.springer.com/chapter/10.1007/978-3-642-39038-8_29 https://sci-hub.tw/https://link.springer.com/chapter/10.1007...
- repsilat 7y agoThat article talks about map and filter and fold, but I think there are also (trickier) ways to make joins and sorts work as well. I think it could be a great technique for a lot of things -- compilers and database views, in addition to front-end state.