Jesús López González, PhD Student, Universidad Rey Juan Carlos & Habla Computing S.L., Spain
Optics provide rich abstractions and composition patterns to access and manipulate immutable data structures. However, the state of real applications is mostly handled through databases, caches, web services, etc. In this effectful setting, the usefulness of optics is severely limited, whereas algebraic theories, thanks to their potential to abstract away from particular infrastructures, shine. Unfortunately, there is a severe lack of standard algebraic theories, e.g. like MonadState, that programmers can reuse to avoid writing their domain repositories from scratch. In this talk, we argue that optics can serve as a fruitful metaphor to design a rich catalogue of state-based algebras, and focus on the paradigmatic case of lenses. We show how lenses can be generalised into an algebraic theory; how compositionality of these algebraic theories can be founded on lens composition; and how to exploit the resulting abstractions in the modular design of data layers. We will use Coq to illustrate examples, definitions and proofs (LensAlgebra). Last, we will briefly introduce Stateless, a Scala library to bring optic algebras to the masses.