4.10. DiffArray

Diff arrays have immutable interface (Section 4.17), but rely on internal updates in place to provide fast functional update operator (//).


So if a diff array is used in a single-threaded style, i.e. after (//) application the old version is no longer used, a!i takes O(1) time and a // d takes O(length d). Accessing elements of older versions gradually becomes slower.


An arbitrary MArray type living in the IO monad can be converted to a diff array with the type constructor IOToDiffArray. It has kind (* -> * -> *) -> * -> * -> *, where parameters mean the following:

Two most important diff array types are fully polymorphic lazy boxed DiffArray = IOToDiffArray IOArray, and strict unboxed DiffUArray = IOToDiffArray IOUArray, working only for elements of primitive types, but more compact and usually faster. These type constructors should be applied to the index type and element type, providing an array type which is an instance of IArray.