一句话:提出 CRPT:可组合递归模式与变换,将递归类型定义用于无回溯的线性时间识别与变换,并给出类型系统与实现。
传统模式匹配和直接递归函数在歧义(非确定性)数据处理中难以避免回溯,常导致代码复杂、模块性差。论文提出可组合递归模式与变换(CRPT),其行为类似结构类型语言中的递归类型定义,可无缝组合以进行类型检查,同时具有运行时语义:被编译为无回溯代码,在输入线性时间、模式多项式时间内识别并变换数据。CRPT 既可作为数据模式验证结构化 JSON 等输入,也能类型安全地变换数据。作者形式化了 CRPT 的动态语义、静态类型系统及其到高效代码的翻译,并在 MLscript 中实现,与若干已有方法对比评估。
Data processing using traditional pattern matching syntax and direct recursive functions is straightforward to write but becomes awkward in ambiguous (i.e., nondeterministic) cases: when programmers wish to avoid backtracking, they often end up having to write complicated code that sacrifices clarity and modularity. However, when the tree language being matched is regular, better solutions are possible. This paper presents composable recursive patterns and transformations (CRPTs), a new programming language feature designed to tackle this problem. CRPTs resemble and act like recursive type definitions in a structurally-typed language, which can be composed seamlessly to type check programs, but they also have a runtime component: they are compiled into backtracking-free code that recognizes and transforms their input in linear time. They serve both to validate existing data—for example, when checking structured JSON input against a CRPT that acts as a data schema—and to transform data in a type-safe and efficient manner. We formalize the dynamic semantics of CRPTs, a static type system for them, and a translation into efficient code that executes in time linear in the size of the input and polynomial in the size of the pattern. We also demonstrate the practicality of CRPTs with an implementation in the MLscript programming language, which we evaluate against comparable existing approaches on several examples.
@article{paperbot12082,
title = {Programming with Composable Recursive Patterns and Transformations},
author = {Luyu Cheng and Florent Ferrari and Michael D. Adams and Lionel Parreaux},
journal = {Proceedings of the ACM on Programming Languages},
volume = {10},
number = {OOPSLA2},
year = {2026},
doi = {10.1145/3839500}
}