Profunctor Optics: Modular Data Accessors

Profunctor Optics: Modular Data Accessors
复制标题

Profunctor Optics:模块化数据访问器

DOI:
10.22152/programming-journal.org/2017/1/7
复制
发表时间:
2017
期刊:
Art Sci. Eng. Program.
影响因子:
--
通讯作者:
Nicolas Wu
Nicolas Wu
中科院分区:
--
文献类型:
--
作者:
Matthew Pickering;J. Gibbons;Nicolas Wu

文献摘要

参考文献

被引文献

相似文献

上下文:数据访问器允许用户读写数据结构的组件,如记录的字段、联合的变体或容器的元素。这些数据访问器统称为光学组件;它们是处理复杂数据的程序的基础。查询:简单数据结构的单个数据访问器很容易编写,例如作为一对“getter”和“setter”方法。然而,如何组合数据访问器并不明显,这样一来,复合数据结构的数据访问器由该结构各部分的较小数据访问器组成。通常,人们必须编写一系列语句或声明,在数据结构中一步一步地导航,一次访问一个级别-这就是说,数据访问者传统上不是一等公民,可以根据自己的权利进行组合。方法:我们提出了一种模块化数据访问框架,其中简单数据结构的单个数据访问器可以自由组合,以获得复合数据结构的更复杂的数据访问器。数据访问者成为一等公民。该框架基于Prounctor的概念,这是对函数的灵活概括。知识:所需的语言特性是高阶函数(“lambdas”或“闭包”)、参数化类型(“泛型”或“抽象类型”),以及用于将接口与实现分离的某种机制(“抽象类”或“模块”)。我们使用Haskell作为呈现构造的工具,但Java、C#或Scala等提供必要功能的语言应该也能很好地工作。基础:我们以文字程序的形式提供了我们所有结构的实现:论文的手稿文件也是程序的源代码,提取的代码可以单独用于评估。我们还证明了这些基本性质,证明了我们的基于Prounctor的表示与更常见的具体表示是精确等价的。重要:我们的结果应该为编写访问复合数据结构组件的程序的更简单方法铺平道路。
CONTEXT: 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. INQUIRY: 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. APPROACH: 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. KNOWLEDGE: The language features required are higher-order functions ("lambdas" or "closures"), parametrized types ("generics" or "abstract types"), 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 languages such as Java, C#, or Scala that provide the necessary features should work just as well. GROUNDING: 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. We also prove the essential properties demonstrating that our profunctor-based representations are precisely equivalent to the more familiar concrete representations. IMPORTANCE: Our results should pave the way to simpler ways of writing programs that access the components of compound data structures.
DOI: 10.1145/2503778.2503781
发表时间: 2013
期刊: --
影响因子: --
作者:
Bird R
通讯作者: Bird R