The Essence of The Iterator Pattern
Jeremy Gibbons and Bruno C. d. S. Oliveira abstract
The ITERATOR pattern gives a clean interface for element-by-element access to a collection, in- dependent of the collection's shape. Imperative iterations using the pattern have two simultaneous aspects: mapping and accumulating. Various existing functional models of iteration capture one or other of these aspects, but not both simultaneously. We argue that McBride and Paterson's applicative functors, and in particular the corresponding traverse operator, do exactly this, and therefore capture the essence of the ITERATOR pattern. Moreover, they do so in a way that nicely supports modular programming. We present some axioms for traversal, discuss modularity concerns, and illustrate with a simple example, the wordcount problem.
infoeditor | Conor McBride and Tarmo Uustalo |
issn | 3-4 |
journal | Journal of Functional Programming |
month | July |
pages | 377-402 |
volume | 19 |
year | 2009 |
links
BibTeX
Link (pdf)
related pages
|