paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Visitors unchained

不受束缚的 Visitors
ICFP 1(ICFP)2017匹配度 2/10 · 论文属于函数式编程与语言设计中的 AST 遍历和名字绑定技术,可为实现静态分析或程序变换提供基础设施;但未涉及 LLM/Agent、静态分析算法、浮点程序分析或贝叶斯程序分析,与研究方向的核心交叉点较远。引用 8 inbox
François Pottier
dblp: 2026-09-10crossref: 2026-09-10

AI 速览

一句话:提出 OCaml 的 Visitors 类型导向生成器与 alphaLib 库,使含名字绑定的 AST 遍历与变换可组合、可定制且模块化。

在 OCaml 中正确、简洁、模块化且可定制地遍历和变换含名字绑定的抽象语法树十分困难。论文把访问者类视为对 AST 操作的可组合局部描述,提出类型导向工具 Visitors,可自动生成不感知绑定结构的访问者类;同时给出 alphaLib,一个由手写小型访问者类组成的库,每个类封装特定绑定构造、名字表示或 AST 操作。通过组合这些组件,可定义广泛操作,支持多种名字表示及其转换,并允许以编程风格编写访问者方法或以声明式绑定组合子描述绑定结构。该工作表明 Visitor 与绑定关注点可分离,从而提升 AST 处理的复用性与模块化。

问题
如何在 OCaml 中正确、简洁、模块化且可定制地遍历与变换带名字绑定的抽象语法树。
方法
将 visitor 类视为可组合的局部描述,提供类型导向的 visitor 类生成器 Visitors;并用 alphaLib 中手写的小型访问者类封装特定绑定构造、名字表示与 AST 操作。
评估
通过组合 Visitors 与 alphaLib 来展示可定义广泛 AST 操作,支持多种名字表示及其转换,并兼容编程式与声明式两种绑定结构描述方式。
原文摘要(Abstract)

Traversing and transforming abstract syntax trees that involve name binding is notoriously difficult to do in a correct, concise, modular, customizable manner. We address this problem in the setting of OCaml, a functional programming language equipped with powerful object-oriented features. We use visitor classes as partial, composable descriptions of the operations that we wish to perform on abstract syntax trees. We introduce "visitors", a simple type-directed facility for generating visitor classes that have no knowledge of binding. Separately, we present "alphaLib", a library of small hand-written visitor classes, each of which knows about a specific binding construct, a specific representation of names, and/or a specific operation on abstract syntax trees. By combining these components, a wide range of operations can be defined. Multiple representations of names can be supported, as well as conversions between representations. Binding structure can be described either in a programmatic style, by writing visitor methods, or in a declarative style, via preprogrammed binding combinators.

链接与引用

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

BibTeX
@article{Pottier17,
  title = {Visitors unchained},
  author = {François Pottier},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {1},
  number = {ICFP},
  year = {2017},
  doi = {10.1145/3110272}
}