Backtracking iterators

  • Authors:
  • Jean-Christophe Filliâtre

  • Affiliations:
  • CNRS -- LRI, Université Paris Sud, Orsay, France

  • Venue:
  • Proceedings of the 2006 workshop on ML
  • Year:
  • 2006

Quantified Score

Hi-index 0.00

Visualization

Abstract

Iterating over the elements of an abstract collection is usually done in ML using a fold-like higher-order function provided by the data structure. This article discusses a different paradigm of iteration based on purely functional, immutable cursors. Contrary to fold-like iterators, the iteration can be cleanly interrupted at any step. Contrary to imperative cursors (such as those found in C++ and Java libraries) it is possible to backtrack the iterator to a previous step. Several ways to iterate over binary trees are examined and close links with Gérard Huet's Zipper are established. Incidentally, we show the well-known two-lists implementation of functional queues arising from a Zipper-based breadth-first traversal.