What’s on my mind is when a small part of a complex data structure is modified, one must traverse from the root to that part to update the whole.
For the children of the part being modified, one can effectively dereference. Why can’t we dereference the direct parent of that part, saving us the trouble of traversing the rest of the data structure?
The implementation would be adding a reference to its parent on the part. Then, its immediate parent could be accessed (without the need to traverse from the root to the part to be modified), and that parent could mutably dereference to the modified child.
Because a reference was changed and not any independent data, the benefits of immutability would be preserved–as one cannot concurrently modify a single parent. AND, one can concurrently modify its children, and then dereference to the parent. In this sense, adding mutable dereferencing actually makes concurrency more powerful in an immutable language… we should add it to Elixir!
How could this be implemented? Have I missed any pitfalls?
And just to recap, I am highlighting the distinction between mutating data and mutating references in relation to concurrency. The latter is okay because the datum depends on the other, meaning it can’t be modified concurrently anyways!






















