[论文解读] A Framework for Resource Dependent EDSLs in a Dependently Typed Language (Pearl)
本文提出 Dependent Haskell,这是对 Haskell 的向后兼容扩展,通过一种新颖的类型系统和编译管道实现完整的依赖类型。它引入了 Pico 作为中间表示语言,并提出了 Bake 类型推断与展开算法,证明了类型安全与正确性,使具备丰富静态保证的实用、可验证程序成为可能。
Haskell, as implemented in the Glasgow Haskell Compiler (GHC), has been adding new type-level programming features for some time. Many of these features---chiefly: generalized algebraic datatypes (GADTs), type families, kind polymorphism, and promoted datatypes---have brought Haskell to the doorstep of dependent types. Many dependently typed programs can even currently be encoded, but often the constructions are painful. In this dissertation, I describe Dependent Haskell, which supports full dependent types via a backward-compatible extension to today's Haskell. An important contribution of this work is an implementation, in GHC, of a portion of Dependent Haskell, with the rest to follow. The features I have implemented are already released, in GHC 8.0. This dissertation contains several practical examples of Dependent Haskell code, a full description of the differences between Dependent Haskell and today's Haskell, a novel type-safe dependently typed lambda-calculus (called Pico) suitable for use as an intermediate language for compiling Dependent Haskell, and a type inference and elaboration algorithm, Bake, that translates Dependent Haskell to type-correct Pico.
研究动机与目标
- 设计并实现一种向后兼容的 Haskell 扩展,支持完整的依赖类型。
- 为一种广泛使用的函数式语言中的依赖类型编程提供实用且类型安全的基础。
- 通过一种新颖的中间语言(Pico)和展开算法(Bake),形式化类型系统与类型推断过程。
- 证明 Pico 的类型安全性和 Bake 的正确性,确保依赖类型的正确编译。
- 支持实际应用,如长度索引向量、类型安全的数据库访问以及强类型解释器。
提出的方法
- 设计一种名为 Pico 的依赖类型 lambda 演算作为编译 Dependent Haskell 的中间语言。
- 定义一种类型推断与展开算法 Bake,将 Dependent Haskell 代码转换为类型正确的 Pico 表达式。
- 引入一种新颖的类型等价关系 ≡ 和提取运算符 →≡,以支持类型级别计算与推理。
- 使用上下文的关联表示法(Rel(Γ))来建模类型级别依赖关系,并在展开过程中确保正确性。
- 通过在类型推导结构上进行结构归纳,证明 Pico 的类型安全性和形式化类型系统属性。
- 通过一系列引理证明 Bake 的正确性,表明在 ⌈·⌉ 操作下,类型正确的 Pico≡ 推导可映射为类型正确的 Pico 推导。
实验结果
研究问题
- RQ1如何以向后兼容的方式将完整的依赖类型添加到 Haskell 中?
- RQ2何种中间语言适合用于编译依赖类型程序,同时保持类型安全?
- RQ3在存在类型级别函数和依赖类型的情况下,如何可靠地执行类型推断与展开?
- RQ4对于依赖类型中间语言及其编译管道,可以证明哪些形式化属性(例如类型安全、正确性)?
- RQ5是否可以在该扩展类型系统中表达并验证实际的、现实世界的程序(例如类型安全的解释器、代数效应)?
主要发现
- Pico 语言为依赖类型程序提供了最小化且形式化正确的中间表示,具有明确定义的类型系统和类型安全的形式化证明。
- Bake 算法成功地将 Dependent Haskell 代码转换为类型正确的 Pico 表达式,其正确性通过关于上下文、类型和协度提升的一系列引理得到证明。
- ⌈·⌉ 操作正确地将类型正确的 Pico≡ 推导映射为等价的 Pico 推导,保留了在 ≡ 和 →≡ 关系下的类型与协度。
- 该框架支持实际应用,如长度索引向量、类型安全的数据库访问以及强类型解释器,证明了其在现实世界中的可行性。
- 形式化证明了 Pico 的类型安全性和 Bake 的正确性,相关证明包含在附录中,为系统奠定了坚实的理论基础。
- GHC 8.0 中关键特性(如 GADTs、类型家族、种类多态性)的实现,证实了该方法的实际可行性。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。