Reference. What you needa know about Yoneda: profunctor optics and the Yoneda lemma (functional pearl)
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.
Cite
Cited by (2)
Insights from Univalent Foundations: A Case Study Using Double Categories rasekh-2025-insights
Category theory unifies mathematical concepts, aiding comparisons across structures by incorporating not just objects, but also morphisms capturing interactions between objects. Of particular importance in some applications are double categories, which are categories with two classes of morphisms, axiomatizing two different kinds of interactions between objects. These have found applications in many areas of mathematics and theoretical computer science, for instance, the study of lenses, open systems, and rewriting. However, double categories come with a wide variety of equivalences, which makes it challenging to transport structure along equivalences. To deal with this challenge, we propose the univalence maxim: each notion of equivalence of categorical structures has a corresponding notion of univalent categorical structure which induces that notion of equivalence. We also prove corresponding univalence principles, which allow us to transport structure and properties along equivalences. In this way, the usually informal practice of reasoning modulo equivalence becomes grounded in an entirely formal logical principle. We apply this perspective to various double categorical structures, such as (pseudo) double categories and double bicategories. Concretely, we characterize and formalize their definitions in Coq UniMath up to chosen equivalences, which we achieve by establishing their univalence principles.
Profunctor Optics, a Categorical Update clarke-2024-profunctor
Optics are bidirectional data accessors that capture data transformation patterns such as accessing subfields or iterating over containers. Profunctor optics are a particular choice of representation supporting modularity, meaning that we can construct accessors for complex structures by combining simpler ones. Profunctor optics have previously been studied only in an unenriched and non-mixed setting, in which both directions of access are modelled in the same category. However, functional programming languages are arguably better described by enriched categories; and we have found that some structures in the literature are actually mixed optics, with access directions modelled in different categories. Our work generalizes a classic result by Pastro and Street on Tambara theory and uses it to describe mixed V-enriched profunctor optics and to endow them with V-category structure. We provide some original families of optics and derivations, including an elementary one for traversals. Finally, we discuss a Haskell implementation.
Cites 41 works (4 here)
With notes (4)
Profunctor Optics: Modular Data Accessors pickering-2017-profunctor
The essence of the Iterator pattern gibbons-2009-the
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.
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.
Categories for the Working Mathematician maclane_1971
External (37)
- I Clean, Therefore I Am (2018)
- lens library, version 4.16 (2018)
- Yoneda and Coyoneda Trick (2017)
- APLicative Programming with Naperian Functors (2017)
- Profunctor Optics: The Categorical Approach (2017)
- Profunctor Optics: The Categorical View (2017)
- Closure Conversion as CoYoneda (2017)
- Free delivery (functional pearl) (2016)
- Category Theory in Context (2016)
- A Representation Theorem for Second-Order Functionals (2015)
- Applicative bidirectional programming with lenses (2015)
- Grate: A new kind of Optic (2015)
- profunctors library, version 5 (2015)
- mezzolens library, version 0 (2015)
- Mainline Profunctor Hierarchy for Optics (2014)
- Co-Yoneda Lemma (2013)
- Arrows are strong monads (2010)
- Reason isomorphically! (2010)
- CPS-Based Functional References (2009)
- The Continuation Passing Transform and the Yoneda Embedding (2008)
- Bidirectional model transformations in QVT: semantic issues and open questions (2008)
- Reverse Engineering Machines with the Yoneda Lemma (2006)
- Category Theory (2006)
- Combinators for bi-directional tree transformations (2005)
- What is a Naperian Container? (2005)
- Program Construction: Calculating Implementations from Specifications (2003)
- The Topos of Music (2002)
- Temporal Algebra (2002)
- The joy of formula manipulation (2001)
- The Yoneda Lemma: What's It All About? (2000)
- Why Preorders Are Beautiful (1991)
- The Concatenate Vanishes (1987)
- A novel representation of lists and its application to the function “reverse” (1986)
- The promotion and accumulation strategies in transformational programming (1984)
- Update semantics of relational views (1981)
- Fragment über Musik und Sprache (1956)
- Leçon Inaugurale du Cours de Poétique du Collège de France. Reprinted in Variété V (1937)