paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Staging with class: a specification for typed template Haskell

带类型类的分阶段编程:类型化 Template Haskell 的一个规范
POPL 6(POPL)2022匹配度 1/10 · 该论文研究 Typed Template Haskell 中 staged type class constraints 的类型健全性,属于纯语言设计与类型系统形式化,与用户关注的静态分析、LLM/Agent、浮点程序分析和贝叶斯程序分析均无直接关联。引用 17 inbox
Ningning Xie, Matthew Pickering, Andres Löh, Nicolas Wu, Jeremy Yallop, Meng Wang
crossref: 2026-09-10

AI 速览

一句话:提出 staged type class constraints,形式化为源演算 λ⇒ 与核心演算 F,证明类型健全性,解决代码引用与类型类的不健全交互。

多阶段编程常借助带类型安全的代码引用(typed quotation)来编写优化代码生成器,但在 Haskell 中代码引用与类型类(type class)交互不健全,导致分阶段程序难以正确编写。本文研究这一不健全性,并提出 staged type class constraints 作为解决方案,将其形式化为源演算 λ⇒,并精化到显式核心演算 F。作者证明了两个演算的类型健全性,即类型良好且分阶段良好的源程序总能精化为类型良好且分阶段良好的核心程序,同时给出了代码引用的 beta 与 eta 规则。该设计以 Haskell 为动机,但也可作为支持重载与引用的其他语言的基础。

问题
在支持代码引用的多阶段编程语言中,引用与类型类的交互不健全,使得编写健壮的分阶段程序十分困难。
方法
提出 staged type class constraints,构造源演算 λ⇒ 并精化到显式核心演算 F,证明两个演算的类型健全性与代码引用的 beta/eta 规则。
评估
以形式化定理证明的方式验证:证明源程序精化后仍保持类型良好与分阶段良好,并给出引用的 beta/eta 规则;以 Haskell 为动机实例。
原文摘要(Abstract)

Multi-stage programming using typed code quotation is an established technique for writing optimizing code generators with strong type-safety guarantees. Unfortunately, quotation in Haskell interacts poorly with type classes, making it difficult to write robust multi-stage programs. We study this unsound interaction and propose a resolution, staged type class constraints, which we formalize in a source calculus λ ⇒ that elaborates into an explicit core calculus F . We show type soundness of both calculi, establishing that well-typed, well-staged source programs always elaborate to well-typed, well-staged core programs, and prove beta and eta rules for code quotations. Our design allows programmers to incorporate type classes into multi-stage programs with confidence. Although motivated by Haskell, it is also suitable as a foundation for other languages that support both overloading and quotation.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@article{paperbot1547,
  title = {Staging with class: a specification for typed template Haskell},
  author = {Ningning Xie and Matthew Pickering and Andres Löh and Nicolas Wu and Jeremy Yallop and Meng Wang},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {6},
  number = {POPL},
  year = {2022},
  doi = {10.1145/3498723}
}