Free Foil: 生成高效且作用域安全的抽象语法
Free Foil: Generating Efficient and Scope-Safe Abstract Syntax
AI总结:
本文提出两种方法使 foil 更易用:结合自由作用域单子生成高效类型安全的抽象语法,并提供 Template Haskell 函数从朴素表示自动生成作用域安全表示,以 $λΠ$ 为例验证并给出基准测试。
摘要:
在编译器、证明助手和定理证明器的实现中,正确处理绑定标识符并保证效率是至关重要的。在为带绑定器的抽象语法选择表示方式时,实现者面临着内在作用域的类型安全、效率和通用性之间的权衡。Maclaurin、Radul 和 Paszke 提出的“foil”方法,通过 Haskell 中高级类型系统特性(如 rank-2 多态和广义代数数据类型),将 Barendregt 约定的高效实现与内在作用域相结合。另一方面,Kudasov 的自由作用域单子将内在作用域与 de Bruijn 索引结合为嵌套数据类型,并采用 Swierstra 的 à la carte 数据类型方法,以支持高阶统一等算法的通用实现。在本文中,我们提出了两种使 foil 更易用的方法。首先,我们将自由作用域单子与 foil 结合,使得对于任何给定二阶签名的语言,都能生成高效、类型安全且通用的带绑定器的抽象语法表示。其次,我们提供了 Template Haskell 函数,可以从朴素表示生成作用域安全表示。后一种方法使我们能够利用现有工具(如 BNF Converter)非常快速地原型化语言的完整实现,包括解析、美观打印和高效的内在作用域抽象语法。我们以带有配对和模式的 $λΠ$ 作为示例对象语言来演示这两种方法。最后,我们提供了基准测试,将我们的实现与 foil、带嵌套 de Bruijn 索引的自由作用域单子以及一些传统实现进行比较。
英文摘要:
Handling bound identifiers correctly and efficiently is critical in implementations of compilers, proof assistants, and theorem provers. When choosing a representation for abstract syntax with binders, implementors face a trade-off between type safety with intrinsic scoping, efficiency, and generality. The "foil" by Maclaurin, Radul, and Paszke combines an efficient implementation of the Barendregt convention with intrinsic scoping through advanced type system features in Haskell, such as rank-2 polymorphism and generalized algebraic data types. Free scoped monads of Kudasov, on the other hand, combine intrinsic scoping with de Bruijn indices as nested data types with Sweirstra's data types à la carte approach to allow generic implementation of algorithms such as higher-order unification. In this paper, we suggest two approaches of making the foil more affordable. First, we marry free scoped monads with the foil, allowing to generate efficient, type-safe, and generic abstract syntax representation with binders for any language given its second-order signature. Second, we provide Template Haskell functions that allow generating the scope-safe representation from a naïve one. The latter approach enables us to use existing tools like BNF Converter to very quickly prototype complete implementation of languages, including parsing, pretty-printing, and efficient intrinsically scoped abstract syntax. We demonstrate both approaches using $λΠ$ with pairs and patterns as our example object language. Finally, we provide benchmarks comparing our implementation against the foil, free scoped monads with nested de Bruijn indices, and some traditional implementations.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。