Next: fingertrees ctors, Up: fingertrees [Contents][Index]
Fingertrees are a generalised form of deque, that we can parameterise to compute a value, called the “measure” of a fingertree. This measure will be updated incrementally as we add and remove elements from the fingertree. Among other things, this allows fingertrees to be used where you otherwise might have written a custom data structure.
To compute the measure, fingertrees require pieces of information: a converter, a combiner, and an identity.
(combine A (combine B C)) ≡ (combine (combine A B) C)
for all values A
, B
and C
.
(combine X identity)
, (combine identity X)
and X
are always the same.
To make things more concrete, a simple use of a fingertree is as a deque that keeps a running total.
In this case, the converter can simply be the function (lambda (x) x)
if it is a deque of
integers, the combiner would be +
, and the identity 0
.
(define l '(3 1 4 1 5 9)) (define ft (list->fingertree l 0 + (lambda (x) x))) (fingertree-measure ft) ⇒ 23 (fingertree-measure (fingertree-snoc ft 2)) ⇒ 25 (let-values (((head tail) (fingertree-uncons ft))) (fingertree-measure tail)) ⇒ 20
Mathematically speaking, the return type of the converter, the combiner and the identity element are expected to form a monoid.
Next: fingertrees ctors, Up: fingertrees [Contents][Index]
This document describes version 0.5.0-devel.1 of MMCK PFDS.