一句话:提出基于子类型与不相交关系的通用类型差运算,将记录上的删除/更新操作推广到函数与交集类型。
在带记录、对象或 trait 的语言中,删除、更新、重命名组件的操作常见,但既有研究多限于记录类型。本文提出:给定子类型关系和不相交关系,可规约并推导通用类型差算子的算法实现,使其适用于函数类型、记录类型和交集类型。该类型差代数具备减法算子的期望性质,并与通用合并算子结合,统一泛化文献中的多种记录操作。作者构造了一个可对任意类型表达式使用丰富算子的中间演算,并在面向组合式编程的原型语言 CP 中展示应用;其语义通过精化为带不相交交集类型与合并算子的演算给出。类型差及所有算子已在 CP 中实现,相关演算与证明均在 Coq 中机器化。
In programming languages with records, objects, or traits, it is common to have operators that allow dropping, updating or renaming some components. These operators are useful for programmers to explicitly deal with conflicts and override or update some components. While such operators have been studied for record types, little work has been done to generalize and study their theory for other types. This paper shows that, given subtyping and disjointness relations, we can specify and derive algorithmic implementations for a general type difference operator that works for other types, including function types, record types and intersection types. When defined in this way, the type difference algebra has many desired properties that are expected from a subtraction operator. Together with a generic merge operator, using type difference we can generalize many operations on records formalized in the literature. To illustrate the usefulness of type difference we create an intermediate calculus with a rich set of operators on expressions of arbitrary type, and demonstrate applications of these operators in CP , a prototype language for Compositional Programming . The semantics of the calculus is given by elaborating into a calculus with disjoint intersection types and a merge operator. We have implemented type difference and all the operators in the CP language. Moreover, all the calculi and related proofs are mechanically formalized in the Coq theorem prover.
@article{paperbot2066,
title = {Making a Type Difference: Subtraction on Intersection Types as Generalized Record Operations},
author = {Han Xu and Xuejing Huang and Bruno C. d. S. Oliveira},
journal = {Proceedings of the ACM on Programming Languages},
volume = {7},
number = {POPL},
year = {2023},
doi = {10.1145/3571224}
}