Data accessors allow one to read and write components of a data structure, such as the fields of a record, the variants of a union, or the elements of a container. These data accessors are collectively known as optics; they are fundamental to programs that manipulate complex data. Individual data accessors for simple data structures are easy to write, for example as pairs of “getter” and “setter” methods. However, it is not obvious how to combine data accessors, in such a way that data accessors for a compound data structure are composed out of smaller data accessors for the parts of that structure. Generally, one has to write a sequence of statements or declarations that navigate step by step through the data structure, accessing one level at a time - which is to say, data accessors are traditionally not first-class citizens, combinable in their own right.
We present a framework for modular data access, in which individual data accessors for simple data structures may be freely combined to obtain more complex data accessors for compound data structures. Data accessors become first-class citizens. The framework is based around the notion of profunctors, a flexible generalization of functions. The language features required are higher-order functions (“lambdas” or “closures”), parametrized types (“generics” or “abstract types”) of higher kind, and some mechanism for separating interfaces from implementations (“abstract classes” or “modules”). We use Haskell as a vehicle in which to present our constructions, but other languages such as Scala that provide the necessary features should work just as well. We provide implementations of all our constructions, in the form of a literate program: the manuscript file for the paper is also the source code for the program, and the extracted code is available separately for evaluation. Our results should pave the way to simpler ways of writing programs that access the components of compound data structures.
Thu 6 AprDisplayed time zone: Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna change
10:45 - 12:15 | |||
10:45 30mTalk | Application Embedding: A Language Approach to Declarative Web Programming Research Papers Link to publication DOI | ||
11:15 30mTalk | Profunctor Optics: Modular Data Accessors Research Papers Matthew Pickering , Jeremy Gibbons Department of Computer Science, University of Oxford, Nicolas Wu University of Bristol Link to publication DOI | ||
11:45 30mTalk | Miscomputation in software: Learning to live with errors Research Papers Tomas Petricek Alan Turing Institute Link to publication DOI |