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
Cited by (5)
Breadth-First Traversal via Staging gibbons-2022-breadth
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 .
Algorithmics bird-2021-algorithmics
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.
Profunctor Optics: Modular Data Accessors pickering-2017-profunctor
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.
External (37)
- Haskell hierarchical libraries (2006)
- Design patterns as higher-order datatype-generic programs (2006)
- The essence of the iterator pattern (2006)
- Fission for program comprehension (2006)
- Combining datatypes and effects (2005)
- Haskell's overlooked object system (2005)
- Origami programming (2003)
- The Haskell 98 Language and Libraries: The Revised Report (2003)
- Generic Haskell: Practice and theory (2003)
- Calculating functional programs (2002)
- Polytypic data conversion programs (2002)
- When is a function a fold or an unfold? (2001)
- Derivable type classes (2001)
- Reverse program calculation supported by code slicing (2001)
- Do we need dependent types? (2000)
- Internal Iteration Externalized (1999)
- Monads, shapely functors and traversals (1999)
- The functional imperative: Shape! (1998)
- PolyP—a polytypic programming language extension (1997)
- Functional programming with overloading and higher-order polymorphism (1995)
- Applicative functors and fully transparent higher-order modules (1995)
- A semantics for shape (1995)
- Design Patterns: Elements of Reusable Object-Oriented Software (1995)
- Merging monads and folds for functional programming (1995)
- Monadic maps and folds for arbitrary datatypes (1994)
- Monads for functional programming (1993)
- Combining Monads (1993)
- Imperative functional programming (1993)
- Using program slicing in software maintenance (1991)
- Functional programming with bananas, lenses, envelopes and barbed wire (1991)
- Notions of computation and monads (1991)
- Tupling and mutumorphisms (1990)
- Why Functional Programming Matters (1989)
- Theorems for free! (1989)
- The C Programming Language (1988)
- Types, abstraction and parametric polymorphism (1983)
- Distributive laws (1969)