Infinite persistence
An infinite value may have a finite representation.
Consider an infinite sequence representing exponential decay in IvoryScript:
let {
decay :: Double -> Exp [Double];
decay x = x :+ decay (x * 0.9)
} in
drop 100 (decay 1.0)
The sequence generated by decay 1.0 begins:
1.0, 0.9, 0.81, 0.729, ...
and continues without bound. The drop 100
expression denotes the same sequence with its first 100 elements
omitted.
2.65614e-05, 2.39053e-05, 2.15147e-05, 1.93633e-05, ...
The resulting expression remains lazy at more than one level:
> typeOf (drop 100 (decay 1.0)) -- Exp (Exp [Double])
One expression layer contains the application of
drop; its potential value is itself a lazy
list.
This is significant for persistence. Copying and persistence are intrinsic operations on IvoryScript values and do not require all lazy parts of a value to be reduced.
Thus the expression containing drop 100 may therefore itself
be persisted. Appropriate use of #! provides
complete control over exactly when the computation to drop the
first 100 items happens - either before insertion, leaving only
the remaining sequence, or or left as a lazy value to be reduced
later. Either way, the remaining sequence itself is lazy.
On reconstruction, the persisted lazy values continue to denote further elements of the sequence. There is no requirement to traverse the infinite value in order to copy or persist it.
There are practical limits. Each represented element must itself have a finite representation, and obtaining or displaying a particular element must take a practicable amount of time and other resources. An infinite value being representable does not imply that every part of it is practically accessible.
The important distinction is that copying and persistence concern the finite representation of a value. That representation may denote an unbounded continuation.