6 ms·
Since HVM is linear, adding some mutability would be completely fine and would NOT break referential transparency (because values only exist in one place!). So,
by LightMachine 5y ago
Since 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 ```