双向类型切片
摘要
本文提出了一种双向类型切片理论:选取一个项并查询其类型信息后,可得到一个足以解释该类型的最小程序切片。该元理论已用 Agda 形式化,并为 Hazel 编程环境实现了一个线性时间的近似算法。
<p>Abstract: Development tools report what type an expression has, but not why it has that type. This paper develops a theory of type slicing that answers such questions: a programmer selects a term, queries any part of the type information associated with it, and receives a slice of the program—a well-formed partial program with irrelevant sub-terms folded away—that suffices to reproduce the queried type. We formulate type slicing for bidirectional type systems, where synthesis slices explain the type a term synthesises and analysis slices explain the type its surrounding context expects. The theory requires no cast dynamics as it applies to any bidirectional system equipped with a precision order on types and terms satisfying a downwards static graduality property.</p>
<p>We develop the metatheory over a core calculus with holes, products, sums, and explicit polymorphism, based on the Hazelnut and marked lambda calculi, proving that every query has a minimal slice, and that refining a
query monotonically shrinks its minimal slices. We then show how to calculate these slices both exactly and approximately. Finally, integrating type slicing with error marking theory extends these results to arbitrary
ill-typed programs, so a single mechanism explains both types and type errors in complete, incomplete, and erroneous code. The metatheory is mechanised in Agda, and a linear-time approximation of type slicing is
implemented for the Hazel programming environment</p>
<p><a href="https://lobste.rs/s/odew1t/bidirectional_type_slicing">Comments</a></p>
查看缓存全文
缓存时间: 2026/10/06 15:25
# Bidirectional Type Slicing Source: [https://arxiv.org/abs/2607.12197](https://arxiv.org/abs/2607.12197) [View PDF](https://arxiv.org/pdf/2607.12197) > Abstract:Development tools report what type an expression has, but not why it has that type\. This paper develops a theory of type slicing: a programmer selects a term, queries any part of its type information, and receives a program slice that is sufficient to reproduce the queried type\. We formulate type slicing for bidirectional type systems, where synthesis slices explain the type a term synthesises and analysis slices explain the type expected by its surrounding context\. The theory applies to any bidirectional system equipped with precision orders on types and terms satisfying a downwards static graduality property\. We develop the metatheory over a core calculus with holes, products, sums, and explicit polymorphism, based on the Hazelnut and marked lambda calculi\. We prove that every query has a minimal slice and that refining a query monotonically shrinks its minimal slices\. We then show how to calculate these slices both exactly and approximately\. Finally, integrating type slicing with error marking theory extends these results to arbitrary ill\-typed programs, so a single mechanism explains both types and type errors in complete, incomplete, and erroneous code\. The metatheory is mechanised in Agda, and a linear\-time approximation of type slicing is implemented for the Hazel programming environment\. ## Submission history From: Max Carroll \[[view email](https://arxiv.org/show-email/9b84bb16/2607.12197)\] **\[v1\]**Mon, 13 Jul 2026 22:53:56 UTC \(445 KB\)
相似文章
Lisp 子类型中(对我来说)意外的行为
本文探讨了在 Common Lisp 的 SBCL 中,数组子类型对整数类型有效,但对受限类型如 (unsigned-byte 16) 失败的意外行为,这归因于编译器优化和升级的数组元素类型。
揭秘类型(及一些悖论的解惑)
类型理论为编程语言基础增加了不必要的复杂性,并提出基于关系成员的更简单观点。
类型推断(第一部分)
关于类型推断的教程,涵盖Damas-Hindley-Milner类型系统、合一及相关概念,并附有OCaml代码示例。
记录类型推断入门指南
本文解释了静态类型语言中匿名记录类型推断的基础知识,使用了类型理论符号并以Haskell作为实现语言。
记录拼接的机械化类型推断
本文对Mitchell Wand在1991年提出的偏记录拼接类型推断算法进行了机械化,提供了声明式与算法式语义,并给出了Haskell参考实现,以推动Nix及其他语言的类型检查进展。