Skip to main content
QUICK REVIEW

[Paper Review] Profunctor optics and traversals

Mario Román|arXiv (Cornell University)|Jan 22, 2020
Homotopy and Cohomology in Algebraic TopologyMathematics31 references8 citations
TL;DR

This paper presents a unified profunctor-based framework for optics, including traversals, using Tambara modules and coend calculus. It derives traversals as coalgebras of a shape-contents comonad, establishes the profunctor representation theorem via Pastro-Street comonad, and shows that composition of optics requires refined notions like clear optics to model Haskell's semantics faithfully.

ABSTRACT

Optics are bidirectional accessors of data structures; they provide a powerful abstraction of many common data transformations. This abstraction is compositional thanks to a representation in terms of profunctors endowed with an algebraic structure called Tambara module. There exists a general definition of optic in terms of coends that, after some elementary application of the Yoneda lemma, particularizes in each one of the basic optics. Traversals used to be the exception; we show an elementary derivation of traversals and discuss some other new derivations for optics. We relate our characterization of traversals to the previous ones showing that the coalgebras of a comonad that represents and split into shape and contents are traversable functors. The representation of optics in terms of profunctors has many different proofs in the literature; we discuss two ways of proving it, generalizing both to the case of mixed optics for an arbitrary action. Categories of optics can be seen as Eilenberg-Moore categories for a monad described by Pastro and Street. This gives us two different approaches to composition between profunctor optics of different families: using distributive laws between the monads defining them, and using coproducts of monads. The second one is the one implicitly used in Haskell programming; but we show that a refinement of the notion of optic is required in order to model it faithfully. We provide experimental implementations of a library of optics in Haskell and partial Agda formalizations of the profunctor representation theorem.

Motivation & Objective

  • To provide a compositional, algebraic framework for optics using profunctors and Tambara modules.
  • To derive traversals as coalgebras of a shape-contents comonad, linking them to traversable functors.
  • To formalize the profunctor representation theorem for optics using coend calculus and Yoneda lemma.
  • To resolve modularity issues in optics composition by introducing clear optics and coproducts of monads.
  • To implement and verify the theory via experimental Haskell libraries and partial Agda formalizations.

Proposed method

  • Uses coend calculus and the Yoneda lemma to derive canonical forms of optics from a general coend definition.
  • Represents optics as profunctors equipped with Tambara module structure, encoding action compatibility.
  • Applies the Pastro-Street construction to define a comonad whose algebras correspond to traversals.
  • Characterizes traversals as coalgebras of the shape-contents comonad, with linearity and unitarity enforced by coalgebra laws.
  • Introduces clear optics to refine composition, enabling faithful modeling of Haskell's optics via coproducts of monads.
  • Employs Kan extensions and right adjoints to establish adjunctions between traversable functors and cofree constructions.

Experimental results

Research questions

  • RQ1How can traversals be systematically derived from a general optic definition using coend calculus?
  • RQ2What is the categorical characterization of traversals as coalgebras of a comonad, and how does it relate to traversable functors?
  • RQ3How can profunctor optics be composed across different families using distributive laws or coproducts of monads?
  • RQ4What refinement of the optic concept is necessary to faithfully model composition in functional programming languages like Haskell?
  • RQ5Can the profunctor representation theorem be generalized to mixed optics with arbitrary monoidal actions?

Key findings

  • Traversals are characterized as coalgebras of the shape-contents comonad, with linearity and unitarity arising from the coalgebra axioms.
  • The profunctor representation theorem is proven via the Pastro-Street comonad, showing that optics correspond to profunctors with Tambara module structure.
  • The category of optics arises as an Eilenberg-Moore category for a monad, providing a categorical foundation for composition.
  • Clear optics are introduced as a refinement to model composition faithfully, particularly in the context of coproducts of monads.
  • The cofree traversal construction is formalized in Agda, showing that $KH$ is the cofree traversal over $H$ via right Kan extensions.
  • An adjunction $\mathbf{Trv}(T, KH) \cong [\mathbf{Sets}, \mathbf{Sets}]({\cal U}T, H)$ is established, proving $KH$ is cofree.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.