Lenses are bidirectional transformations between pairs of connected structures. Asymmetric lenses —where one of those two connected structures is taken to be primary —have been extensively studied. Lenses were first proposed to solve the viewupdate problem of tree-like data structures by Foster et. al[4] and have also been applied to the construction of a relational database query language[2]. Other work has altered the primitive structure of lenses to achieve different results[5]. We begin by exploring the existing utilities available for bidirectional transformations in the Scala programming language. We discuss the associated problems with these utilities using examples and propose a solution using asymmetric lenses. We present the canonical representation of an asymmetric lens and an alternative representation which is particularly suited to the specific properties of the Scala programming language and which has desirable properties for users. We explore a small set of interesting user libraries that arise as a consequence of integrating asymmetric lenses into Scala, chosen for the purpose of demonstrating utility. We will also take a brief look at partial lenses —applicable to sum types, which Scala directly supports. Finally, we briefly examine existing requirements, solutions and proposals for integrating lenses into the Scala programming language.
[1]
Benjamin C. Pierce,et al.
Relational lenses: a language for updatable views
,
2006,
PODS '06.
[2]
Russell O'Connor.
Functor is to Lens as Applicative is to Biplate: Introducing Multiplate
,
2011,
ArXiv.
[3]
Benjamin C. Pierce,et al.
Combinators for bi-directional tree transformations: a linguistic approach to the view update problem
,
2005,
POPL '05.
[4]
Mark P. Jones,et al.
Functional Programming with Overloading and Higher-Order Polymorphism
,
1995,
Advanced Functional Programming.
[5]
Benjamin C. Pierce,et al.
Quotient lenses
,
2008,
ICFP 2008.