Papers
Topics
Authors
Recent
Search
2000 character limit reached

Type Theory With Erasure

Published 1 May 2026 in cs.PL and cs.LO | (2605.00655v1)

Abstract: Erasure enriches type theory with a distinction between runtime relevant and irrelevant data, allowing the compilation step to safely erase the latter. Versions of this feature are implemented by many systems, including Agda, Idris, and Rocq. We present a structural version of type theory with erasure, formulated as a second-order generalised algebraic theory (SOGAT). Erasure is encoded as a phase distinction between runtime and erased terms, in the form of a proposition that can appear in a context. This formulation has several advantages: it has models based on categories with families, is compatible with other structural features such as staging, and provides a better guideline for implementation. Through the model theory of SOGATs, we study the semantics of type theory with erasure in families of sets, which generalises to any Grothendieck topos equipped with a tiny proposition. We establish conservativity over Martin-Löf type theory (MLTT) in both phases. For code extraction, we construct a presheaf model that produces untyped lambda calculus programs and prove its correctness through gluing. Our results are formalised in Agda and we provide a toy elaborator implementation.

Summary

  • The paper introduces a novel SOGAT-based reformulation of MLTT that encodes erasure as a first-class syntactic and semantic feature.
  • It establishes key metatheoretical properties, including conservativity and the zeroing property, ensuring erased data remains independent and computationally inert.
  • The work underpins a canonical code extraction method that maps runtime terms to untyped lambda calculus with trusted extraction semantics.

Type Theory With Erasure: A Structural, SOGAT-based Reformulation

Introduction and Objectives

"Type Theory With Erasure" (2605.00655) presents a new algebraic and structural approach to the concept of erasure in dependent type theories, leveraging the formalism of second-order generalised algebraic theories (SOGATs). Unlike previous approaches—most notably Quantitative Type Theory (QTT)—this work formulates erasure as a phase distinction encoded synthetically at the propositional level within type theory. The approach yields a fully structural extension of Martin-Löf Type Theory (MLTT), compatible with other modular features such as staging, and is concretely modeled in both syntactic and semantic terms.

The core innovation is to make erasure a first-class syntactic and semantic feature, rather than encoding it operationally via annotations or analyses. This is achieved by introducing an erasure marker #\# into contexts, allowing precise phase management: terms and types are classified as runtime-relevant or erased, with explicit mutual coercions governed by the presence of the erasure proposition. The syntactic, semantic, and implementation-level implications of this are thoroughly analyzed.

Formalisation via SOGAT, GAT Translation, and Erasure Marker

The foundation is laid with a SOGAT specification that structurally internalizes the concepts of runtime (mode ω\omega) and erased (mode $0$) terms within the type theory. Erasure is realized not by substructural side conditions or linearity constraints but by introducing a specific propositional sort #\#—the erasure marker—together with isomorphisms $(\downtm, \uptm)$ facilitating the transition between runtime and erased terms according to context.

Contexts are extended either by term variables (runtime or erased) or by erasure markers. In an erased context (#∈Γ\# \in \Gamma), explicit rules enable $\uptm$ (lifting an erased term to runtime) and $\downtm$ (demoting a runtime term to erased under erasure). These operations are shown to be mutually inverse up to definitional equality within the system.

The SOGAT is translated to a first-order generalised algebraic theory (GAT), yielding a traditional type-theoretic syntax (with variables, contexts, substitutions). Key features such as Π/Σ\Pi/\Sigma types, universes, and inductive types are extended with mode indices, systematically distinguishing erased and runtime data in both types and terms.

Syntactic and Metatheoretical Properties

The paper proves several essential metatheorems, establishing that the proposed system maintains key properties expected of a well-behaved extension of MLTT:

  • Zeroing Property: All erased terms are independent of runtime data. There exists a zeroing morphism mapping any context, type, and term to its erased fragment, yielding a natural bijection between erased terms in a context and terms in the zeroed context.
  • Conservativity: Both the runtime and erased fragments of the type theory with erasure are conservative over the corresponding fragments in ordinary MLTT. That is, any theorem derivable in the extended system projects back to a theorem in MLTT, ensuring logical compatibility. Theorem-level surjectivity is established, though full isomorphism fails due to mode-dependent binders.
  • Independence of Erased and Runtime Data: The erasure mechanism enforces a strict separation between the computationally relevant and irrelevant phases. The erased fragment is shown not to introduce new computational behaviour; erased functions are necessarily constant at runtime.

Semantic Models: Gluing and Squashed Universes

Semantics are provided via an interpretation into categories with families (CwFs), as well as a detailed family-of-sets model, and generalized to Grothendieck toposes with a tiny proposition:

  • Erasure in Semantic Models: The erasure marker #\# is interpreted as a proposition (the single-fiber family ω\omega0 in ω\omega1), and exponentiation by this proposition effects the transition from runtime to erased data.
  • Squashed Universes: The system requires universes that are "squashed" (modal with respect to the erasure marker) to model erased types. The right adjoint to exponentiation by the tiny proposition (i.e., squashed universes) is constructed, justifying the existence and structure of erased universes in ω\omega2 and general Grothendieck toposes.
  • Modularity and Gluing: The model theory is modular and supports additional features by combining the SOGAT with other modular extensions (e.g., to two-level type theory). Gluing is used to relate code extraction with logical semantics, providing the framework required for correctness proofs.

Code Extraction and Correctness

The practical outcome is a code extraction procedure targeting the untyped lambda calculus: after typechecking, only runtime data and computationally relevant code are retained in the compiled output.

  • Model Construction: A specific ω\omega3-CwF morphism interprets the erasure type theory into the presheaf category over the first-order model of untyped lambda calculus, mapping runtime fragment to executable code and mapped erased structure to trivial data.
  • Extraction Maps: Extraction is canonical and aligns with the runtime-relevant semantics: closed runtime terms are mapped to closed lambda terms, and the number of runtime variables in context determines the arity of the extracted term.
  • Logical Relations and Glued Models: The correctness of extraction is established via a logical relations argument in a glued category. This formalizes that the extracted code not only has the correct arity and shape, but also computes correctly with respect to the set-theoretic interpretation.
  • Strong Claims: The canonicity and non-interference results are precise: erased functions are provably constant, and the extraction of closed terms agrees exactly with their interpretation in ω\omega4.

Implementation Considerations

A reference implementation is presented, built as a modification of Kovács's elaboration-zoo, supporting full coercion insertion and management of the erasure marker. Critically, the use of a structural core and elimination of substructural context management means pattern unification and metavariable generalization become streamlined—elimination of separate mode-run unification or lifting, in contrast to approaches in Idris2 and Agda, which are shown to be brittle or incomplete in this respect.

This approach is positioned relative to:

  • QTT: While QTT employs semiring-based quantification to manage usage and erasure, here the erasure phase distinction is encoded as a synthetic proposition, resulting in a theory that is both simpler and structurally more compatible with modular extensions.
  • Phase Distinction Literature: The method generalizes earlier work on phase distinction ([Sterling2021-pm], [Cardelli1988-zp]), providing a fully algebraic and structural in-type-theory implementation.
  • Other Modal and Ghost Systems: Compared to ghost sorts and color-based type theories, this approach cleanly isolates runtime-irrelevant fragments and is flexible enough to accommodate further modality or phased extensions.

Implications and Future Directions

The formulation allows powerful and predictable erasure in dependently-typed programming, with immediate application in reliable code extraction, theorem-prover kernel implementation, and staging/metaprogramming. The synthetic encoding of phase distinctions generalizes readily to logical and programming language modalities.

Open questions and future directions include:

  • Extending universes to allow runtime types directly, which relaxes the need for squashed universes and further simplifies the model theory.
  • Combining multiple, possibly interacting, phase distinctions via additional markers, enabling more transparent internalized compilation, cross-phase equational reasoning, or staged program optimization reasoning.
  • Deeper analysis and categorical characterization of inductive type signatures with arbitrarily marked erased/retained arguments and constructors.

Conclusion

"Type Theory With Erasure" (2605.00655) establishes a structural, syntactically modular extension to dependent type theory managing erasure via a synthetic phase distinction, backed by a precise SOGAT formulation. It demonstrates both strong metatheoretical properties and compelling practical implications for type theory implementations and code extraction pipelines. The approach’s compatibility with modular extensions and categorical semantics positions it as a rigorous foundation for future developments in modal and dependently-typed programming languages.

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Open Problems

We haven't generated a list of open problems mentioned in this paper yet.

Collections

Sign up for free to add this paper to one or more collections.