=Paper= {{Paper |id=Vol-2999/bxpaper2 |storemode=property |title=Delta Lenses as Coalgebras for a Comonad |pdfUrl=https://ceur-ws.org/Vol-2999/bxpaper2.pdf |volume=Vol-2999 |authors=Bryce Clarke |dblpUrl=https://dblp.org/rec/conf/staf/Clarke21 }} ==Delta Lenses as Coalgebras for a Comonad== https://ceur-ws.org/Vol-2999/bxpaper2.pdf
Delta lenses as coalgebras for a comonad
Bryce Clarke
Centre of Australian Category Theory, Macquarie University, Sydney, Australia


                                      Abstract
                                      Delta lenses are a kind of morphism between categories which are used to model bidirectional trans-
                                      formations between systems. Classical state-based lenses, also known as very well-behaved lenses, are
                                      both algebras for a monad and coalgebras for a comonad. Delta lenses generalise state-based lenses, and
                                      while delta lenses have been characterised as certain algebras for a semi-monad, it is natural to ask if
                                      they also arise as coalgebras.
                                          This short paper establishes that delta lenses are coalgebras for a comonad, through showing that
                                      the forgetful functor from the category of delta lenses over a base, to the category of cofunctors over
                                      a base, is comonadic. The proof utilises a diagrammatic approach to delta lenses, and clarifies several
                                      results in the literature concerning the relationship between delta lenses and cofunctors. Interestingly,
                                      while this work does not generalise the corresponding result for state-based lenses, it does provide new
                                      avenues for exploring lenses as coalgebras.

                                      Keywords
                                      delta lens, cofunctor, coalgebra, bidirectional transformation




1. Introduction
The goal of understanding various kinds of lenses as mathematical structures has been an
ongoing program in the study of bidirectional transformations. For example, very well-behaved
lenses [1], also known as state-based lenses [2], have been understood as both algebras for a
monad [3] and coalgebras for a comonad [4, 5]. A generalisation of state-based lenses called
category lenses [6] were also introduced as algebras for a monad, based on classical work in
2-category theory on split opfibrations [7]. Another kind of lens between categories called a
delta lens [8] was shown to be a certain algebra for a semi-monad [9], however it remained
open as to whether delta lenses could also be characterised as (co)algebras for a (co)monad.
   The purpose of this short paper is to characterise delta lenses as coalgebras for a comonad
(Theorem 9). The proof of this simple result builds upon and clarifies several recent advances in
the theory of delta lenses.
   In 2017, Ahman and Uustalu introduced update-update lenses [2] as morphisms of directed
containers [10], which are equivalent to certain morphisms called cofunctors between categories
[11]. In the same paper, they show explicitly how, using the notation of directed containers,
delta lenses may be understood as cofunctors with additional structure.
   In earlier work [12] from 2016, Ahman and Uustalu also provide a construction on morphisms
of directed containers which yields a split pre-opcleavage for a functor; in other words, they
Bx 2021: 9th International Workshop on Bidirectional Transformations, part of STAF, June 21, 2021
" bryce.clarke1@hdr.mq.edu.au (B. Clarke)
 0000-0003-0579-2804 (B. Clarke)
                                    Β© 2021 Copyright for this paper by its authors. Use permitted under Creative Commons License Attribution 4.0 International (CC BY 4.0).
 CEUR
 Workshop
 Proceedings
               http://ceur-ws.org
               ISSN 1613-0073
                                    CEUR Workshop Proceedings (CEUR-WS.org)
show how cofunctors may be turned into delta lenses. We show that this construction is actually
a right adjoint to the forgetful functor from delta lenses to cofunctors (Lemma 8), and that the
coalgebras for the comonad generated from this adjunction are delta lenses (Theorem 9).
   In 2020, a diagrammatic characterisation of delta lenses was introduced by the current author
[13], building upon an earlier characterisation of cofunctors as spans [14]. This diagrammatic
approach is utilised throughout this paper, and leads to another simple characterisation of delta
lenses (Proposition 6).

Overview of the paper and related work
This section provides an informal overview of the paper, together with further commentary
on the background, and references to related work. The goal is to provide a conceptual under-
standing of the results; later sections will be dedicated to the formal mathematics.
   Section 2 contains the mathematical background required for the main results, which are
presented in Section 3. Consequences of the main result and concluding remarks are in Section 4.
   Throughout the paper we make the assumption that a system, whatever that may be, can be
understood as a category. The objects of this category are the states of the system, while the
morphisms are the transitions (or deltas) between system states.
   Delta lenses were introduced in [8, Definition 4] to model bidirectional transformations
between systems when they are understood as categories. The Get of a delta lens is a functor
𝑓 : 𝐴 β†’ 𝐡 from the source category 𝐴 to the view category 𝐡, while the Put is a certain kind
of function (that this paper calls a lifting operation) satisfying axioms analogous to the classical
lens laws. A slightly modified definition of delta lens appeared in [9, Definition 1], however this
definition still seemed to be ad hoc, and made it difficult to prove deep results without checking
many details.
   The definition of delta lens (Definition 4) given in this paper is based on a diagrammatic
characterisation which first appeared in [13, Corollary 20], by representing the Put in terms
of bijective-on-objects functors (Definition 1) and discrete opfibrations (Definition 2). This
diagrammatic approach provides a natural framework for studying delta lenses using category
theory, and has the benefit of allowing for very simple (albeit more abstract) proofs. This
approach will be utilised throughout this paper, although in many places we will also include
explicit descriptions of constructions using the traditional definition of a delta lens.
   A key idea presented in [2, 13] is that the Get and Put of a delta lens can be separated into
functors and cofunctors (Definition 3), respectively. Intuitively, a cofunctor can be understood
as a delta lens without any information on how the Get acts on morphisms; it is the minimum
amount of structure needed to specify a Put operation between categories. It was shown in the
paper [2] that delta lenses are cofunctors with additional structure. In this paper, we aim to
show that said structure arises coalgebraically via a comonad.
   Both delta lenses and cofunctors are predominantly understood and studied as morphisms
between categories, however to prove that delta lenses are cofunctors equipped with coalgebraic
structure, it is necessary for them to be understood as objects. Therefore this paper introduces a
new category Cof(𝐡), whose objects are cofunctors into a fixed category 𝐡 (Definition 5). The
category Lens(𝐡), whose objects are delta lenses into a fixed category 𝐡, was previously studied
in [15, 16]. Surprisingly, we show that the category Lens(𝐡) can be defined (Definition 7) as
the slice category Cof(𝐡)/1𝐡 . Not only does this provide a new characterisation of delta lenses
in term of cofunctors (Proposition 6), but also provides the insight that the canonical forgetful
functor 𝐿 : Lens(𝐡) β†’ Cof(𝐡), which takes a delta lens to its underlying Put cofunctor, is a
projection from a slice category.
   Finally, proving that delta lenses are coalgebras for a comonad on Cof(𝐡) amounts to showing
that the forgetful functor 𝐿 : Lens(𝐡) β†’ Cof(𝐡) is comonadic (Theorem 9). A necessary
condition is that 𝐿 has a right adjoint 𝑅 (Lemma 8), which constructs the cofree delta lens
from each cofunctor in Cof(𝐡). This construction first appeared explicitly in [12, Section 3.2],
however it was not obviously a right adjoint β€” or even a functor β€” and it was disconnected from
the context of cofunctors and delta lenses. Both Lemma 8 and Theorem 9 admit straightforward
proofs, with the benefit of the diagrammatic approach to cofunctors and delta lenses.

Notation and conventions
This section outlines some of the notation and conventions used in the paper. Given a category 𝐴,
its underlying set (or discrete category) of objects is denoted 𝐴0 . Given a functor 𝑓 : 𝐴 β†’ 𝐡,
its underlying object assignment is denoted 𝑓0 : 𝐴0 β†’ 𝐡0 . Similarly, a cofunctor πœ™ : 𝐴 ↛ 𝐡
will have an underlying object assignment πœ™0 : 𝐴0 β†’ 𝐡0 . Thus the orientation of a cofunctor
agrees with the orientation of its underlying object assignment (this convention is chosen to
agree with the orientation of delta lenses, however this choice is not uniform in the literature
on cofunctors). The operation cod sends each morphism to its codomain or target object.


2. Prerequisites for the main result
We first recall two special classes of functors, which we will use as the building blocks for
defining cofunctors and delta lenses. New contributions in this section include the category
Cof(𝐡) whose objects are cofunctors (Definition 5), and the characterisation of delta lenses as
certain morphisms therein (Proposition 6).

Definition 1. A functor 𝑓 : 𝐴 β†’ 𝐡 is bijective-on-objects if its underlying object assignment
𝑓0 : 𝐴0 β†’ 𝐡0 is a bijection.

Definition 2. A functor 𝑓 : 𝐴 β†’ 𝐡 is a discrete opfibration if for all pairs,

                                   (π‘Ž ∈ 𝐴, 𝑒 : 𝑓 π‘Ž β†’ 𝑏 ∈ 𝐡)

there exists a unique morphism 𝑀 : π‘Ž β†’ π‘Žβ€² in 𝐴 such that 𝑓 𝑀 = 𝑒.

Definition 3. A cofunctor πœ™ : 𝐴 ↛ 𝐡 between categories is a span of functors,

                                                𝑋
                                            πœ™       πœ™
                                                                                              (1)
                                        𝐴               𝐡

where πœ™ is a bijective-on-objects functor and πœ™ is a discrete opfibration.
   Alternatively, a cofunctor πœ™ : 𝐴 ↛ 𝐡 consists of a function πœ™0 : 𝐴0 β†’ 𝐡0 , together with
a lifting operation πœ™, which assigns each pair (π‘Ž ∈ 𝐴, 𝑒 : πœ™0 π‘Ž β†’ 𝑏 ∈ 𝐡) to a morphism
πœ™(π‘Ž, 𝑒) : π‘Ž β†’ π‘Žβ€² in 𝐴, such that the following axioms are satisfied:
            (οΈ€       )οΈ€
(1) πœ™0 cod πœ™(π‘Ž, 𝑒) = cod(𝑒);
(2) πœ™(π‘Ž, 1πœ™0 π‘Ž ) = 1π‘Ž ;
(3) πœ™(π‘Ž, 𝑣 ∘ 𝑒) = πœ™(π‘Žβ€² , 𝑣) ∘ πœ™(π‘Ž, 𝑒), where π‘Žβ€² = cod πœ™(π‘Ž, 𝑒) .
                                                     (οΈ€       )οΈ€

Definition 4. A delta lens (𝑓, πœ™) : 𝐴 β‡Œ 𝐡 between categories is a commutative diagram of
functors,
                                           𝑋
                                        πœ™       πœ™
                                                                                     (2)
                                        𝐴       𝑓
                                                        𝐡

where πœ™ is a bijective-on-objects functor and πœ™ is a discrete opfibration.

  We can also describe a delta lens (𝑓, πœ™) : 𝐴 β‡Œ 𝐡 as consisting of a functor 𝑓 : 𝐴 β†’ 𝐡
together with a lifting operation πœ™, which assigns each pair (π‘Ž ∈ 𝐴, 𝑒 : 𝑓 π‘Ž β†’ 𝑏 ∈ 𝐡) to a
morphism πœ™(π‘Ž, 𝑒) : π‘Ž β†’ π‘Žβ€² in 𝐴, such that the following axioms are satisfied:
(1) 𝑓 πœ™(π‘Ž, 𝑒) = 𝑒;
(2) πœ™(π‘Ž, 1𝑓 π‘Ž ) = 1π‘Ž ;
(3) πœ™(π‘Ž, 𝑣 ∘ 𝑒) = πœ™(π‘Žβ€² , 𝑣) ∘ πœ™(π‘Ž, 𝑒), where π‘Žβ€² = cod πœ™(π‘Ž, 𝑒) .
                                                     (οΈ€      )οΈ€

  Every delta lens (𝑓, πœ™) : 𝐴 β‡Œ 𝐡 has an underlying functor 𝑓 : 𝐴 β†’ 𝐡 and an underlying
cofunctor πœ™ : 𝐴 ↛ 𝐡, and their corresponding underlying object assignments are equal; that is,
𝑓0 = πœ™0 .

Definition 5. For each category 𝐡, there is a category Cof(𝐡) of cofunctors over the base 𝐡
whose objects are cofunctors with codomain 𝐡, and whose morphisms are given by commutative
diagrams of functors of the form:

                                                β„Ž
                                        𝐴               𝐢
                                       πœ™                    𝛾
                                                β„Ž                                             (3)
                                       𝑋                π‘Œ
                                            πœ™       𝛾
                                                𝐡

   Equivalently, a morphism in Cof(𝐡) from a cofunctor πœ™ : 𝐴 ↛ 𝐡 to a cofunctor 𝛾 : 𝐢 ↛ 𝐡
consists of a functor β„Ž : 𝐴 β†’ 𝐢 such that 𝛾0 β„Žπ‘Ž = πœ™0 π‘Ž for all π‘Ž ∈ 𝐴, and β„Žπœ™(π‘Ž, 𝑒) = 𝛾(β„Žπ‘Ž, 𝑒)
for all pairs (π‘Ž ∈ 𝐴, 𝑒 : πœ™0 π‘Ž β†’ 𝑏 ∈ 𝐡). The functor β„Ž : 𝑋 β†’ π‘Œ is then uniquely induced from
this data. Intuitively, if 𝐴 and 𝐢 are understood as source categories with a fixed view category
𝐡, then the morphisms in Cof(𝐡) are functors between the source categories which preserve
the chosen lifts, given by the corresponding cofunctors, from the view category.
Proposition 6. Every delta lens (𝑓, πœ™) : 𝐴 β‡Œ 𝐡 is equivalent to a morphism in Cof(𝐡) whose
codomain is the trivial cofunctor on 𝐡.

Proof. Consider the morphism in Cof(𝐡) given by the commutative diagram of functors:

                                                        𝑓
                                           𝐴                 𝐡
                                           πœ™                     1𝐡
                                                        πœ™                                      (4)
                                           𝑋                 𝐡
                                                πœ™           1𝐡
                                                        𝐡

The upper commutative square describes a delta lens as given in Definition 4. Conversely, every
delta lens may be depicted as a morphism in Cof(𝐡) in this way.

   We can unpack (4) using the explicit characterisation of morphisms in Cof(𝐡) to obtain the
precise difference between cofunctors and delta lenses, in terms of objects and morphisms.
Namely, the diagram (4) states that a delta lens corresponds to a cofunctor πœ™ : 𝐴 ↛ 𝐡 together
with a functor 𝑓 : 𝐴 β†’ 𝐡 such that 𝑓 π‘Ž = πœ™0 π‘Ž for all π‘Ž ∈ 𝐴, and 𝑓 πœ™(π‘Ž, 𝑒) = 𝑒 for all pairs
(π‘Ž ∈ 𝐴, 𝑒 : 𝑓 π‘Ž β†’ 𝑏 ∈ 𝐡).

Definition 7. For each category 𝐡, we define the category of delta lenses over the base 𝐡 to be
the slice category Lens(𝐡) := Cof(𝐡) / 1𝐡 , where 1𝐡 is the trivial cofunctor on 𝐡.

 By Proposition 6, the objects of Lens(𝐡) are delta lenses with codomain 𝐡, represented as a
morphism into the trivial cofunctor as shown in (4). The morphisms in Lens(𝐡) are given by
morphisms (3) in Cof(𝐡) such that the following pasting condition holds:

                       β„Ž               𝑔                                      𝑓
               𝐴              𝐢                     𝐡                 𝐴            𝐡
              πœ™                   𝛾                 1𝐡                πœ™                1𝐡
                          β„Ž            𝛾                     =                πœ™                (5)
               𝑋              π‘Œ                     𝐡                 𝑋            𝐡
                                  𝛾
                      πœ™                    1𝐡                             πœ™       1𝐡
                              𝐡                                               𝐡

In other words, the only additional requirement on a morphism β„Ž : 𝐴 β†’ 𝐢 between delta lenses
over 𝐡, compared to a morphism between cofunctors over 𝐡, is that 𝑔 ∘ β„Ž = 𝑓 . This is opposed
to just requiring 𝛾0 β„Žπ‘Ž = πœ™0 π‘Ž on objects (where recall for delta lenses, the underlying object
assignments for the functor and cofunctor are equal, that is, 𝑔0 = 𝛾0 and 𝑓0 = πœ™0 ).
   There is a canonical forgetful functor,

                                      𝐿 : Lens(𝐡) βˆ’β†’ Cof(𝐡)

which assigns every delta lens to its underlying cofunctor. This forgetful functor is the focus of
the main result in the following section.
3. Main result
While not every cofunctor may be given the structure of a delta lens, Ahman and Uustalu [12]
developed a method which constructs a delta lens from any cofunctor. To understand their
construction, first recall that the underlying objects functor (βˆ’)0 : Cat β†’ Set has a right adjoint
(βˆ’)
 Μ‚οΈ€ : Set β†’ Cat which takes each set 𝑋 to the codiscrete category 𝑋.   Μ‚οΈ€
   Given a cofunctor πœ™ : 𝐴 ↛ 𝐡 with underlying object assignment πœ™0 : 𝐴0 β†’ 𝐡0 , we may
construct the following pullback in Cat:
                                                 𝑃
                                            πœ‹π΄             πœ‹π΅




                                                 ⌟
                                      𝐴                         𝐡                               (6)
                                     Μ‚οΈ€0 ∘ πœ‚π΄
                                     πœ™                     πœ‚π΅
                                                 𝐡
                                                 Μ‚οΈ€0

Here πœ‚π΅ : 𝐡 β†’ 𝐡  Μ‚οΈ€0 is the component of the unit for the adjunction at 𝐡, and πœ™   Μ‚οΈ€0 ∘ πœ‚π΄ the
component of the unit at 𝐴 followed by image of πœ™0 under the right adjoint. Using the universal
property of the pullback, we have the following:
                                                 𝑋
                                        πœ™          βŸ¨πœ™,πœ™βŸ©        πœ™

                                                 𝑃
                                            πœ‹π΄             πœ‹π΅                                   (7)
                                                 ⌟




                                      𝐴                         𝐡
                                     Μ‚οΈ€0 ∘ πœ‚π΄
                                     πœ™                     πœ‚π΅
                                                 𝐡
                                                 Μ‚οΈ€0

Since πœ‚π΅ is bijective-on-objects, the projection functor πœ‹π΄ is also bijective-on-objects which,
together with the functor πœ™, implies that βŸ¨πœ™, πœ™βŸ© : 𝑋 β†’ 𝑃 is bijective-on-objects, due to the
properties of bijections at the level of objects. Thus, the upper right triangle in (7) defines a
delta lens 𝑃 β‡Œ 𝐡.
   The category 𝑃 has the same objects as 𝐴, but morphisms π‘Ž β†’ π‘Žβ€² in 𝑃 are given by pairs
of the form (𝑀 : π‘Ž β†’ π‘Žβ€² ∈ 𝐴, 𝑒 : πœ™0 π‘Ž β†’ πœ™0 π‘Žβ€² ∈ 𝐡). The functor πœ‹π΅ : 𝑃 β†’ 𝐡 projects to
the second arrow in this pair. The lifting operation which makes this functor into a delta lens
is induced by the lifting operation of the original                              )οΈ€ π‘Ž ∈ 𝑃 and a
                                                      cofunctor; it takes an object
morphism 𝑒 : πœ™0 π‘Ž β†’ 𝑏 ∈ 𝐡 to the morphism πœ™(π‘Ž, 𝑒) : π‘Ž β†’ π‘Žβ€² , 𝑒 : πœ™0 π‘Ž β†’ 𝑏 in 𝑃 .
                                                 (οΈ€

   We now show that this construction due to Ahman and Uustalu is universal, in the sense
that it provides a right adjoint to the functor taking a delta lens to its underlying cofunctor.
Lemma 8. The forgetful functor 𝐿 : Lens(𝐡) β†’ Cof(𝐡) has a right adjoint.
Proof. Using the construction in (7), define the functor 𝑅 : Cof(𝐡) β†’ Lens(𝐡) by the assign-
ment:
                       𝑋                                           𝑋
                   πœ™        πœ™                                βŸ¨πœ™,πœ™βŸ©     πœ™
                                              β†¦βˆ’β†’                                        (8)
                  𝐴              𝐡                                  𝑃   πœ‹π΅    𝐡
We describe the components of the unit and counit for the adjunction 𝐿 ⊣ 𝑅 and omit the
detailed checks that the triangle identities hold.
  Given a cofunctor πœ™ : 𝐴 ↛ 𝐡 the component of the counit is given by:
                                                          πœ‹π΄
                                             𝑃                        𝐴
                                       βŸ¨πœ™,πœ™βŸ©                          πœ™

                                             𝑋                        𝑋                          (9)

                                                 πœ™                πœ™
                                                          𝐡

  Given a delta lens (𝑓, πœ™) : 𝐴 β‡Œ 𝐡 the component of the unit is given by:

                    ⟨1𝐴 ,𝑓 ⟩           πœ‹π΅                                         𝑓
               𝐴               𝑃                 𝐡                        𝐴            𝐡
              πœ™                βŸ¨πœ™,πœ™βŸ©                 1𝐡                   πœ™                1𝐡
                                       πœ™                          =               πœ™             (10)
               𝑋               𝑋                 𝐡                        𝑋            𝐡
                               πœ™
                     πœ™                  1𝐡                                    πœ™       1𝐡
                               𝐡                                                  𝐡

The above diagrams show that the pasting condition required in (5) is satisfied.

Theorem 9. The forgetful functor 𝐿 : Lens(𝐡) β†’ Cof(𝐡) is comonadic.

Proof. By Lemma 8, the functor 𝐿 has a right adjoint 𝑅. To prove that 𝐿 is comonadic, it remains
to show that the category of coalgebras for the induced comonad 𝐿𝑅 on Cof(𝐡) is equivalent
to Lens(𝐡).
   Given a cofunctor πœ™ : 𝐴 ↛ 𝐡, a coalgebra structure map is given by a morphism in Cof(𝐡)
of the form:
                                              β„Ž
                                     𝐴               𝑃
                                       πœ™                          βŸ¨πœ™,πœ™βŸ©
                                                     β„Ž                                          (11)
                                        𝑋                         𝑋
                                             πœ™                πœ™
                                                     𝐡
However compatibility with the counit forces β„Ž = 1𝑋 and β„Ž = ⟨1𝐴 , 𝑓 ⟩, where 𝑓 : 𝐴 β†’ 𝐡 is a
functor such that 𝑓 ∘ πœ™ = πœ™. Compatibility with the comultiplication doesn’t add any further
conditions. Therefore, a coalgebra for the comonad 𝐿𝑅 on Cof(𝐡) is equivalent to a delta lens
(𝑓, πœ™) : 𝐴 β‡Œ 𝐡.

  This theorem establishes the result stated in the title of the paper, that delta lenses (2) are
coalgebras (11) for a comonad.
4. Concluding remarks
In this paper, the category Lens(𝐡) of delta lenses over the base 𝐡 was characterised as the
category of coalgebras for a comonad on the category Cof(𝐡) of cofunctors over the base 𝐡. This
brings together recent results in the study of delta lenses and cofunctors. In particular, we have
shown that the extra structure on cofunctors given in Ahman and Uustalu’s [2] characterisation
of delta lenses is coalgebraic, and that their construction of a delta lens from cofunctor in the
paper [12] is precisely the cofree delta lens on a cofunctor. Throughout we have also shown
how the abstract diagrammatic approach to delta lenses, first introduced in [13], has led to
concise proofs of these results, and offers a clear perspective on the relationship between these
ideas.
   Aside from clarification and development of theory, the results presented in this paper have
several other mathematical consequences. For example, the functor 𝐿 : Lens(𝐡) β†’ Cof(𝐡)
creates all colimits which exist in Cof(𝐡). Thus we can take the coproduct of a pair of cofunctors
in Cof(𝐡), and automatically know how to construct the coproduct of the corresponding delta
lenses in Lens(𝐡).
   Another consequence from the unit (10) of the adjunction between Cof(𝐡) and Lens(𝐡) is
that every delta lens factorises into a bijective-on-objects functor followed by a cofree lens.
Intuitively, this allows us to first pair every transition in the source category 𝐴 with a transition
in the view category 𝐡 via the functor part 𝑓 : 𝐴 β†’ 𝐡 of the delta lens,
             𝑀 : π‘Ž β†’ π‘Žβ€² ∈ 𝐴        β†¦βˆ’β†’        (𝑀 : π‘Ž β†’ π‘Žβ€² ∈ 𝐴, 𝑓 𝑀 : 𝑓 π‘Ž β†’ 𝑓 π‘Žβ€² ∈ 𝐡)
then consider the update propagation determined by the cofunctor part πœ™ : 𝐴 ↛ 𝐡 of the
delta lens. The cofree delta lens on a cofunctor behaves much like an analogue of constant
complement state-based lenses, except that the complement is with respect to morphisms rather
than objects.
   While the main contributions of this paper are mathematical, it is hoped that these results
also prompt new ways of understanding delta lenses. For example, previously state-based lenses
have been considered from a β€œPut-based” perspective [17, 18], however this approach could
also be adapted to the setting of delta lenses. Rather than starting with a Get functor between
systems and then asking how we might construct a delta lens, we might instead start with a
Put cofunctor and then ask for ways in which this can be given the structure of a delta lens.
This shift of focus is subtle but important, especially in the context of the ideas in [2], as it
is arguably the Put structure (rather than the Get structure) which is central to the study of
bidirectional transformations and lenses.
   On an separate note, it is worth remarking on the similarity between the main result of
this paper and the classical result stating that very well-behaved lenses are coalgebras for a
comonad [4, 5]. Despite the clear analogy between them, and the inspiration that this paper
derives from the classical result, it seems that they are unrelated at a mathematical level. The
classical result relies on Set being a cartesian closed category, and arises from the adjunction
(βˆ’) Γ— 𝐡 ⊣ [𝐡, βˆ’], whereas the results in this paper arise from a different adjunction, and don’t
require any aspect of cartesian closure.
   There are many questions to be explored in future work. For instance, it is natural to ask if
Lens(𝐡) is comonadic over other categories (such as Cat as was suggested by an anonymous
reviewer), or if split opfibrations (also known as c-lenses [6]) are also comonadic over Cof(𝐡).
In recent work by the current author, it has been demonstrated that delta lenses arise as algebras
for a monad on Cat/𝐡, providing a dual to the main result of this paper and strengthening the
previous work of Johnson and Rosebrugh [9]. Finally, given the importance of the category
Lens(𝐡) in the study of symmetric lenses [15, 16], it is also hoped that the coalgebraic perspective
provides new insights into this area, and this will be the subject of further investigation.


Acknowledgments
The author would like to thank Michael Johnson for his feedback on this work, the anonymous
reviewers of this paper for their helpful comments, and the audience of the Bx2021 workshop
for their insightful questions. The author also thanks Eli Hazel and Giacomo Tendas for their
suggestions which improved the final version of this paper. The author is grateful for the
support of the Australian Government Research Training Program Scholarship.


References
 [1] J. N. Foster, M. B. Greenwald, J. T. Moore, B. C. Pierce, A. Schmitt, Combinators for
     bidirectional tree transformations: A linguistic approach to the view-update problem,
     ACM Transactions on Programming Languages and Systems 29 (2007) 1–65. doi:10.1145/
     1232420.1232424.
 [2] D. Ahman, T. Uustalu, Taking updates seriously, in: Proceedings of the 6th International
     Workshop on Bidirectional Transformations, volume 1827 of CEUR Workshop Proceedings,
     2017, pp. 59–73. URL: http://ceur-ws.org/Vol-1827/paper11.pdf.
 [3] M. Johnson, R. Rosebrugh, R. Wood, Algebras and update strategies, Journal of Universal
     Computer Science 16 (2010) 729–748. doi:10.3217/jucs-016-05-0729.
 [4] R. O’Connor, Functor is to lens as applicative is to biplate: Introducing multiplate, 2011.
     arXiv:1103.2841.
 [5] J. Gibbons, M. Johnson, Relating algebraic and coalgebraic descriptions of lenses, in: Pro-
     ceedings of the First International Workshop on Bidirectional Transformations, volume 49
     of Electronic Communications of the EASST, 2012, pp. 1–16. doi:10.14279/tuj.eceasst.
     49.726.
 [6] M. Johnson, R. Rosebrugh, R. Wood,           Lenses, fibrations and universal transla-
     tions, Mathematical Structures in Computer Science 22 (2012) 25–42. doi:10.1017/
     S0960129511000442.
 [7] R. Street, Fibrations and Yoneda’s lemma in a 2-category, in: Category Seminar, volume
     420 of Lecture Notes in Mathematics, 1974, pp. 104–133. doi:10.1007/BFb0063102.
 [8] Z. Diskin, Y. Xiong, K. Czarnecki, From state- to delta-based bidirectional model
     transformations: the asymmetric case, Journal of Object Technology 10 (2011) 1–25.
     doi:10.5381/jot.2011.10.1.a6.
 [9] M. Johnson, R. Rosebrugh, Delta lenses and opfibrations, Electronic Communications of
     the EASST 57 (2013) 1–18. doi:10.14279/tuj.eceasst.57.875.
[10] D. Ahman, J. Chapman, T. Uustalu, When is a container a comonad?, Logical Methods in
     Computer Science 10 (2014) 1–48. doi:10.2168/LMCS-10(3:14)2014.
[11] M. Aguiar, Internal Categories and Quantum Groups, Ph.D. thesis, Cornell University,
     1997.
[12] D. Ahman, T. Uustalu, Directed containers as categories, in: Proceedings 6th Workshop on
     Mathematically Structured Functional Programming, volume 207 of Electronic Proceedings
     in Theoretical Computer Science, 2016, pp. 89–98. doi:10.4204/EPTCS.207.5.
[13] B. Clarke, Internal lenses as functors and cofunctors, in: Applied Category Theory 2019,
     volume 323 of Electronic Proceedings in Theoretical Computer Science, 2020, pp. 183–195.
     doi:10.4204/EPTCS.323.13.
[14] P. J. Higgins, K. C. H. Mackenzie, Duality for base-changing morphisms of vector bundles,
     modules, Lie algebroids and Poisson structures, Mathematical Proceedings of the Cam-
     bridge Philosophical Society 114 (1993) 471–488. doi:10.1017/S0305004100071760.
[15] M. Johnson, R. Rosebrugh, Universal updates for symmetric lenses, in: Proceedings of
     the 6th International Workshop on Bidirectional Transformations, volume 1827 of CEUR
     Workshop Proceedings, 2017, pp. 39–53. URL: http://ceur-ws.org/Vol-1827/paper8.pdf.
[16] B. Clarke, A diagrammatic approach to symmetric lenses, in: Applied Category Theory
     Conference 2020, volume 333 of Electronic Proceedings in Theoretical Computer Science,
     2021, pp. 79–91. doi:10.4204/EPTCS.333.6.
[17] H. Pacheco, Z. Hu, S. Fischer, Monadic combinators for putback style bidirectional pro-
     gramming, in: Proceedings of the ACM SIGPLAN 2014 Workshop on Partial Evaluation and
     Program Manipulation, volume 333 of PEPM ’14, 2014, pp. 39–50. doi:10.1145/2543728.
     2543737.
[18] S. Fischer, Z. Hu, H. Pacheco, The essence of bidirectional programming, Science China
     Information Sciences 58 (2015) 1–21. doi:10.1007/s11432-015-5316-8.