Bidirectional Type Slicing

📅 2026-07-13
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
Existing development tools can report the types of expressions but cannot explain how those types arise. This work proposes a theory of bidirectional type slicing, extending type slicing for the first time to bidirectional type systems, thereby unifying type synthesis and contextual expectation. The approach supports complete, incomplete, and erroneous programs. Built upon a core calculus featuring holes, products, sums, and explicit polymorphism, and leveraging a precision order and static gradual guarantee, we formalize the theory in Agda, proving the existence of minimal slices and their monotonic contraction under query refinement. Furthermore, we implement a linear-time approximation algorithm in the Hazel environment.
📝 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.
Problem

Research questions and friction points this paper is trying to address.

type slicing
bidirectional type systems
program explanation
type errors
program slicing
Innovation

Methods, ideas, or system contributions that make the work stand out.

bidirectional type checking
type slicing
program slicing
static graduality
type error explanation