Skip to main content
QUICK REVIEW

[Paper Review] Categories of Optics

Mitchell Riley|arXiv (Cornell University)|Sep 3, 2018
Logic, programming, and type systemsComputer Science16 references17 citations
TL;DR

This paper formalizes the categorical foundation of optics—lenses, prisms, traversals, and related bidirectional data accessors—by defining a general optic construction in symmetric monoidal categories. It introduces a universal functor that freely adds counit morphisms, proves equivalence between its lawfulness definition and folklore profunctor laws, and establishes a rigorous, general framework for lawful optics applicable across diverse mathematical and programming contexts.

ABSTRACT

Bidirectional data accessors such as lenses, prisms and traversals are all instances of the same general 'optic' construction. We give a careful account of this construction and show that it extends to a functor from the category of symmetric monoidal categories to itself. We also show that this construction enjoys a universal property: it freely adds counit morphisms to a symmetric monoidal category. Missing in the folklore is a general definition of 'lawfulness' that applies directly to any optic category. We provide such a definition and show that it is equivalent to the folklore profunctor optic laws.

Motivation & Objective

  • To provide a rigorous, general categorical definition of optics that unifies lenses, prisms, and traversals across arbitrary symmetric monoidal categories.
  • To establish that the optic construction extends to a functor from symmetric monoidal categories to themselves.
  • To define a universal property for the optic construction as freely adding counits to a category of dualisable morphisms.
  • To introduce a general definition of 'lawfulness' for optics that specializes correctly to known cases and enables derivation of laws for new optic types.
  • To prove equivalence between the proposed lawfulness definition and the folklore profunctor encoding laws used in functional programming.

Proposed method

  • Defines optics as a construction in symmetric monoidal categories using coend formulas and comma categories, generalizing concrete optics like lenses.
  • Applies the coend calculus and Yoneda reduction to derive universal properties and isomorphisms, particularly for profunctor encodings.
  • Introduces a new definition of lawfulness via coalgebras for a comonad arising from an adjunction involving Grothendieck construction and slice categories.
  • Uses the Ninja Yoneda Lemma and coend coequalizer construction to verify isomorphisms between concrete and profunctor encodings.
  • Demonstrates that the optic construction is a functor from SymmMonCat to SymmMonCat, preserving structure across categories.
  • Verifies that the proposed lawfulness condition matches the standard profunctor laws used in libraries like Haskell’s lens.

Experimental results

Research questions

  • RQ1How can a uniform categorical framework be constructed to unify lenses, prisms, and other optics in symmetric monoidal categories?
  • RQ2What universal property does the optic construction satisfy, and how does it relate to adding counit morphisms?
  • RQ3Is there a general definition of 'lawfulness' for optics that correctly specializes to known laws for lenses and prisms?
  • RQ4Are the folklore profunctor encoding laws equivalent to the proposed categorical definition of lawfulness?
  • RQ5Can this framework be extended to new settings such as compositional game theory or monad transformers?

Key findings

  • The optic construction forms a functor from the category of symmetric monoidal categories to itself, generalizing the notion of bidirectional accessors.
  • The optic construction satisfies a universal property: it freely adds counit morphisms to a category of dualisable morphisms.
  • A new, general definition of lawfulness for optics is proposed and proven equivalent to the folklore profunctor encoding laws.
  • The construction correctly specializes to known optics: lawful lenses, prisms, and traversals are all instances of the same general optic category.
  • The profunctor encoding of optics is isomorphic to the concrete encoding, and the proposed lawfulness condition matches the standard laws used in functional programming.
  • The framework provides a foundation for extending optics to new domains, such as probabilistic game theory and monad transformer stacks, via a unified categorical lens.

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.