paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Modular Type Safety for Traits with Extensible Variants and Deep Pattern Matching

面向可扩展变体与深层模式匹配的 trait 模块化类型安全
OOPSLA 10(OOPSLA2)2026匹配度 2/10 · 该论文属于类型系统与语言设计,关注 trait、可扩展变体、深层模式匹配和模块化类型安全,虽与静态分析/形式化验证的 PL 基础相关,但完全不涉及 LLM/Agent、机器学习系统、浮点程序分析或贝叶斯程序分析等用户核心方向。引用 0 inbox
Andong Fan, Lionel Parreaux, Ningning Xie
crossref: 2026-10-02

AI 速览

一句话:提出支持可扩展变体、深层模式匹配、方法重写、穷尽性保证与独立类型检查的 trait 语言,实现模块化类型安全。

Traits 支持共享行为的组合与代码复用,Scala 中广泛用于 DSL 编译器;但模式匹配可扩展数据类型时,类型检查通过的程序仍可能因非穷尽匹配在运行时抛出异常。本文提出一种新的 trait 语言,首次同时支持可扩展数据类型、深层模式匹配、方法重写、穷尽性保证与分离类型检查,前三点服务 DSL 分析与优化,后两点支持可靠且可扩展的大型软件开发。方法上,作者在 Boolean-algebraic subtyping 框架中形式化该语言,并说明核心思想可迁移到其他类型系统。该设计使 Scala 等同时具有 trait 与可扩展变体的语言能够实现类型安全,改善 DSL 编译等场景的开发体验。

问题
Scala 等语言中,trait 与可扩展变体结合时,模式匹配可能非穷尽,导致类型检查通过但运行时异常,难以保证模块化类型安全。
方法
提出支持可扩展数据类型、深层模式匹配和方法重写的 trait 语言,并在 Boolean-algebraic subtyping 框架下形式化,以实现可分离类型检查和非穷尽匹配保证。
评估
评估以形式化建模与类型安全性质论证为主,表明核心思想可适用于 Scala 等具有 trait 和可扩展变体的语言。
原文摘要(Abstract)

Traits provide a powerful mechanism for code reuse, as they allow the definition of shared behaviors that can be composed into classes. Scala traits in particular have been used extensively in both academia and industry to help define reusable components, especially in the context of domain-specific language (DSL) compilers. Pattern matching on the extensible data types representing a DSL’s constructs plays a key role in these applications. However, guaranteeing static type safety in this context is challenging: in Scala, a program using traits may successfully type check but then throw a runtime exception due to non-exhaustive pattern matching. This paper proposes a novel trait language which, for the first time, combines several important features: extensible data types, deep pattern matching, method overriding, exhaustiveness guarantees, and separate type checking. The former three are crucial to supporting DSL analysis and optimization use cases, while the latter two are important for reliable and scalable software development in the large. We formalize our approach in the framework of Boolean-algebraic subtyping, but its core ideas could be adapted to other type systems; thanks to it, languages like Scala that feature traits and extensible variants can finally become type safe, improving the experience of developers working with DSL compilation and related use cases.

链接与引用

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

BibTeX
@article{paperbot12085,
  title = {Modular Type Safety for Traits with Extensible Variants and Deep Pattern Matching},
  author = {Andong Fan and Lionel Parreaux and Ningning Xie},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {10},
  number = {OOPSLA2},
  year = {2026},
  doi = {10.1145/3839514}
}