3 ms·
And another question, is this for purely functional code only, or does it / could it also apply to mutable data structures. In particular, is it somehow related
by auggierose 5y ago
And another question, is this for purely functional code only, or does it / could it also apply to mutable data structures. In particular, is it somehow related to copy-on-write techniques (like for example used for Swift's data structures), or is this something entirely different?
- herbstein 5y agoBased on my understanding on the HOW.md text this relies heavily on mathematical equality for performance. In its execution it is essentially constantly inlining operations as it goes.
- LightMachine 5y agoSince HVM is linear, adding some mutability would be completely fine and would NOT break referential transparency (because values only exist in one place!). So, we could actually have "pure mutable arrays". In order to make that mix up well with lazy cloning, though, we'd need to limit the size of array to about 16. But larger arrays could be made as trees of mutable 16-tuples. There was a post about it, but I can't find it right now.
- auggierose 5y agoThat makes sense to me; I am currently implementing a package with mutable data structures with shallow constant time cloning (via copy-on-write) for TypeScript, and the dup idea somehow seems to be compatible with that.
- lcedp 5y agoBut wouldn't it make mutability only useful in local scopes? ``` fn f(x) { *x = 42 // lazily cloning on write }; let x = 1; f(x); // x still equals 1 here ```