Reference. The essence of the Iterator pattern

The Iterator pattern gives a clean interface for element-by-element access to a collection, independent 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 C. McBride and R. Paterson’s applicative functors (Applicative programming with effects, J. Funct. Program. , 18 (1): 1–13, 2008), 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.

Cite

Cite as @gibbons-2009-the (helia, typst) · \cite{gibbons-2009-the} (LaTeX)
BibTeX
bibtex · 3 lines
@article{gibbons-2009-the, title={The essence of the
                    <scp>Iterator</scp>
                    pattern}, volume={19}, ISSN={1469-7653}, url={http://dx.doi.org/10.1017/s0956796809007291}, DOI={10.1017/s0956796809007291}, number={3-4}, journal={Journal of Functional Programming}, publisher={Cambridge University Press (CUP)}, author={GIBBONS, JEREMY and OLIVEIRA, BRUNO C. d. S.}, year={2009}, month=July, pages={377–402} }
hayagriva YAML (typst)
yaml · 18 lines
gibbons-2009-the:
  type: article
  title: The essence of the Iterator pattern
  author:
  - Gibbons, Jeremy
  - name: S. Oliveira
    given-name: Bruno C.
    prefix: d.
  date: 2009-07
  page-range: 377-402
  serial-number:
    doi: 10.1017/s0956796809007291
  parent:
    type: periodical
    title: Journal of Functional Programming
    publisher: Cambridge University Press (CUP)
    issue: 3–4
    volume: 19
Cited by (5)

Breadth-First Traversal via Staging gibbons-2022-breadth

DOI

A type- and scope-safe universe of syntaxes with binding: their semantics and proofs allais-2021-a

The syntax of almost every programming language includes a notion of binder and corresponding bound occurrences, along with the accompanying notions of α-equivalence, capture-avoiding substitution, typing contexts, runtime environments, and so on. In the past, implementing and reasoning about programming languages required careful handling to maintain the correct behaviour of bound variables. Modern programming languages include features that enable constraints like scope safety to be expressed in types. Nevertheless, the programmer is still forced to write the same boilerplate over again for each new implementation of a scope-safe operation (e.g., renaming, substitution, desugaring, printing), and then again for correctness proofs. We present an expressive universe of syntaxes with binding and demonstrate how to (1) implement scope-safe traversals once and for all by generic programming; and (2) how to derive properties of these traversals by generic proving. Our universe description, generic traversals and proofs, and our examples have all been formalised in Agda and are available in the accompanying material available online at https://github.com/gallais/generic-syntax .
PDF · DOI · arXiv · pldb

Algorithmics bird-2021-algorithmics

DOI

What you needa know about Yoneda: profunctor optics and the Yoneda lemma (functional pearl) boisseau-2018-what

Profunctor optics are a neat and composable representation of bidirectional data accessors, including lenses, and their dual, prisms. The profunctor representation exploits higher-order functions and higher-kinded type constructor classes, but the relationship between this and the familiar representation in terms of “getter” and “setter” functions is not at all obvious. We derive the profunctor representation from the concrete representation, making the relationship clear. It turns out to be a fairly direct application of the Yoneda Lemma, arguably the most important result in category theory. We hope this derivation aids understanding of the profunctor representation. Conversely, it might also serve to provide some insight into the Yoneda Lemma.
PDF · DOI · pldb

Profunctor Optics: Modular Data Accessors pickering-2017-profunctor

DOI
Cites 38 works (1 here)
With notes (1)

Applicative programming with effects mcbride-2008-applicative

In this article, we introduce Applicative functors – an abstract characterisation of an applicative style of effectful programming, weaker than Monads and hence more widespread. Indeed, it is the ubiquity of this programming pattern that drew us to the abstraction. We retrace our steps in this article, introducing the applicative pattern by diverse examples, then abstracting it to define the Applicative type class and introducing a bracket notation that interprets the normal application syntax in the idiom of an Applicative functor. Furthermore, we develop the properties of applicative functors and the generic operations they support. We close by identifying the categorical structure of applicative functors and examining their relationship both with Monads and with Arrow.
PDF · DOI · pldb
External (37)
gibbons-2009-the reference entries/refs/gibbons-2009-the/gibbons-2009-the.hel