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

Cite as @boisseau-2018-what (helia, typst) · \cite{boisseau-2018-what} (LaTeX)
BibTeX
bibtex · 1 line
@article{boisseau-2018-what, title={What you needa know about Yoneda: profunctor optics and the Yoneda lemma (functional pearl)}, volume={2}, ISSN={2475-1421}, url={http://dx.doi.org/10.1145/3236779}, DOI={10.1145/3236779}, number={ICFP}, journal={Proceedings of the ACM on Programming Languages}, publisher={Association for Computing Machinery (ACM)}, author={Boisseau, Guillaume and Gibbons, Jeremy}, year={2018}, month=July, pages={1–27} }
hayagriva YAML (typst)
yaml · 16 lines
boisseau-2018-what:
  type: article
  title: 'What you needa know about Yoneda: profunctor optics and the Yoneda lemma (functional pearl)'
  author:
  - Boisseau, Guillaume
  - Gibbons, Jeremy
  date: 2018-07
  page-range: 1-27
  serial-number:
    doi: 10.1145/3236779
  parent:
    type: periodical
    title: Proceedings of the ACM on Programming Languages
    publisher: Association for Computing Machinery (ACM)
    issue: ICFP
    volume: 2
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.
DOI

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.
DOI · arXiv
Cites 41 works (4 here)
With notes (4)

Profunctor Optics: Modular Data Accessors pickering-2017-profunctor

DOI

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.
PDF · DOI · pldb

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

Categories for the Working Mathematician maclane_1971

Web
External (37)
boisseau-2018-what reference entries/refs/boisseau-2018-what/boisseau-2018-what.hel