Theory Lenses_And_Other_Optics.Lens
theory Lens
imports Prism
begin
section‹Lenses: functional references›
text ‹We use a ▩‹lens› or ∗‹functional reference› to model in-place update or reads of
deeply-nested fields within our model of the Rust language. A lens over a record or other
product-like type (e.g., a tuple), here represented by the polymorphic type \<^typ>‹'s›, consists of
two components:
\begin{enumerate*}
\item
A ∗‹view› function which allows us to view, or ``zoom in on'', some field of a record or
product-like datatype. Here, the field of the record is modelled as a polymorphic type \<^typ>‹'a›.
\item
A ∗‹modification› function which allows us to modify a field nested (potentially deeply) within a
record.
\end{enumerate*}
Various laws, introduced later, will be used to ensure that these two functions behave correctly, as
one would expect for a reference-like object, and which will introduce a notion of ∗‹well-formed›
lens.
Mathematically, one can think of as a lens as a ∗‹quotient› with specified lifting operations.›