Next: , Up: fingertrees   [Contents][Index]


7.1 Introduction to fingertrees

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.

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: , Up: fingertrees   [Contents][Index]

This document describes version 0.5.0-devel.1 of MMCK PFDS.