Skip to content

Immutable Value, Mutable Form

Bill La Forge edited this page Oct 1, 2015 · 1 revision

A value can have more than one form or implementation. For example, a String and a char array may both represent the same value. Most objects, for example, can be serialized. Changing the form of a value then is not a change of value. This is the idea behind lazy deserialization / reserialization.

We can represent a data structure as a tree, where the values in the tree can be either the immutable value of the object or a read-only ByteBuffer holding the serialized form of the value, or both. Both forms can be held by nodes using atoms, so the form of the values can be changed without having to create a new tree. The value remains unchanged and the tree can be safely shared between threads. This is the core idea behind the lazy maps and vectors in the aatree project.