Bidirectional Type Slicing
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…
This paper introduces a theory of type slicing for bidirectional type systems, which enables programmers to query specific parts of a program's type information and receive a partial program containing only relevant sub-terms. The theory applies to any bidirectional system with a precision order on types and terms that satisfy a downwards static graduality property.
It is based on a core calculus with holes, products, sums, and explicit polymorphism, as well as the Hazelnut and marked lambda calculi. The metatheory proves that each query has a minimal slice, and refining a query monotonically reduces the size of the minimal slices. The paper demonstrates methods for calculating these slices, both precisely and approximately.
Integrating type slicing with error marking theory extends these results to ill-typed programs, allowing a single mechanism to explain both types and type errors in complete, incomplete, and erroneous code. The metatheory has been mechanized in Agda, and a linear-time approximation of type slicing has been implemented for the Hazel programming environment.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.