面向 ML 的可扩展记录与重载约束之间的灵活可逆转换
Flexible and Reversible Conversion between Extensible Records and Overloading Constraints for ML
AI总结:
本文提出 inject 与 eject 两种类型驱动语言构造,支持在可扩展记录和重载约束之间可逆、可限定范围地转换,以连接字典传递与编译器约束求解并促进库复用。
摘要:
大多数类 ML 函数式语言将记录和重载作为互不相关的特性提供。记录不仅表示数据结构,还用于实现字典传递;而重载会生成类型约束,这些约束本质上是受编译器驱动分派的字典。本文探讨记录与重载约束如何相互转换,使程序员能够以非常合理的语法开销代价在两者之间切换。为此,我们引入两种语言构造,即 inject 和 eject,执行类型驱动的语法变换。前者按字面意义将约束注入类型,并生成一个添加额外记录参数的函数。后者执行相反操作,从函数中弹出一个记录参数,并将字段转换为类型约束。该转换是可逆的,并且可以限制于符号的一个子集,从而赋予程序员额外的控制力。虽然我们称为 inject 的操作在文献中已有提出,但将其作为语言算子并与其逆向对应物相结合,代表了一种新颖设计。目标是让程序员能够从字典传递风格切换到编译器辅助的约束求解,反之亦然,从而实现原本无法互操作的库之间的复用。
英文摘要:
Most ML-like functional languages provide records and overloading as unrelated features. Records not only represent data structures, but are also used to implement dictionary passing, whereas overloading produces type constraints that are basically dictionaries subject to compiler-driven dispatching. In this paper we explore how records and overloading constraints can be converted one into the other, allowing the programmer to switch between the two at a very reasonable cost in terms of syntactic overhead. To achieve this we introduce two language constructs, namely inject and eject, performing a type-driven syntactic transformation. The former literally injects constraints into the type and produces a function adding an extra record argument. The latter does the opposite, ejecting a record argument from a function and turning fields into type constraints. The conversion is reversible and can be restricted to a subset of symbols, granting additional control to the programmer. Although what we call inject has already been proposed in literature, making it a language operator and coupling it with its reverse counterpart represent a novel design. The goal is to allow the programmer to switch from a dictionary-passing style to compiler-assisted constraint resolution, and vice versa, enabling reuse between libraries that otherwise would not interoperate.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。