Papers
Topics
Authors
Recent
Search
2000 character limit reached

A Graded Modal Dependent Type Theory with Erasure, Formalized

Published 31 Mar 2026 in cs.LO and cs.PL | (2603.29716v1)

Abstract: We present a graded modal type theory, a dependent type theory with grades that can be used to enforce various properties of the code. The theory has $Π$-types, weak and strong $Σ$-types, natural numbers, an empty type, and a universe, and we also extend the theory with weak and strong unit types and graded $Σ$-types. The theory is parameterized by a modality structure, a kind of partially ordered semiring, whose elements (grades) are used to track the usage of variables in terms and types. Different modalities are possible. We focus mainly on quantitative properties, in particular erasure: with the erasure modality one can mark function arguments as erasable. The theory is fully formalized in Agda. The formalization, which uses a syntactic Kripke logical relation at its core and is based on earlier work, establishes major meta-theoretic properties such as subject reduction, consistency, normalization, and decidability of definitional equality. We also prove a substitution theorem for grade assignment, and preservation of grades under reduction. Furthermore we study an extraction function that translates terms to an untyped $λ$-calculus and removes erasable content, in particular function arguments with the "erasable" grade. For a certain class of modalities we prove that extraction is sound, in the sense that programs of natural number type have the same value before and after extraction. Soundness of extraction holds also for open programs, as long as all variables in the context are erasable, the context is consistent, and erased matches are not allowed for weak $Σ$-types.

Summary

  • The paper presents a unified framework that formalizes graded modalities and erasure to enforce resource discipline in dependent type theory.
  • It introduces system extensions such as graded Σ-types and security typing with formal proofs of normalization, subject reduction, and decidable equality.
  • The mechanization in Agda validates extraction soundness, ensuring erasable code does not impact program outcomes across different evaluation strategies.

Graded Modal Dependent Type Theory with Erasure: Formalization and Meta-theory

Introduction and Motivation

The paper presents a fully formalized dependent type theory incorporating graded modalities, supporting resource-aware programming disciplines such as erasure, linearity, and information flow via type- and term-level usage annotations. The gradings are parameterized by an algebraic modality structure, typically a partially ordered semiring, used to encode and statically enforce discipline on resource/variable usage. This generalizes and subsumes previous approaches such as Quantitative Type Theory (QTT) and provides a unifying semantic framework for resource-sensitive dependent type systems.

The primary focus of the study is the incorporation and meta-theoretical justification of erasure, enabling static non-computational (proof-irrelevant) portions of programs to be marked and removed at extraction/compilation time without affecting program outcomes. The system integrates grades throughout dependent types and terms, defines precise grading inference and checking mechanisms, and formalizes meta-theoretical results in Agda, including normalization, subject reduction, substitution, and decidability of definitional equality.

Modality Structure and Graded Judgements

Modalities as Algebraic Structures

The resource modalities are modeled as semirings (addition ++, multiplication â‹…\cdot, distinguished zero and one elements, with partial order via a meet operation), general enough to capture common patterns:

  • Erasure: M={0,ω}\mathcal{M} = \{0, \omega\}; $0$ (erasable), ω\omega (computationally relevant).
  • Affineness/Linearity: M={0,1,ω}\mathcal{M} = \{0, 1, \omega\} or further refinements.
  • Information Flow: Distributive lattices; e.g., low (L)(L) and high (H)(H) security levels.

The meta-theory is parameterized over these structures, facilitating proofs and mechanization for a broad class of resource-aware systems.

Graded Dependent Type System

  • Syntax: Dependent Π\Pi- and Σ\Sigma-types, â‹…\cdot0, universe, empty type, weak/strong unit types, graded pairing/abstraction/application. â‹…\cdot1 and â‹…\cdot2 binders and related constructors/case analyses are annotated with grades, controlling resource tracking.
  • Graded Contexts: Usage contexts (mapping variables to grades) are maintained in parallel to typing contexts.
  • Judgement Separation: The system separates usage checking from typing:
    • Typing: â‹…\cdot3.
    • Grading: â‹…\cdot4, where â‹…\cdot5 is a usage context.
    • This supports more flexible resource tracking and is crucial for sound treatment of dependent types.

Erasure Tracking and Well-Behaved Zero Grades

A central technical requirement is a well-behaved zero in the modality, supporting static reasoning about erasability. Multiple positivity conditions (addition, meet, natural number recursion, zero-product) ensure that variables marked as erasable cannot affect computation or values without the programmer’s intent.

Formal Properties and Meta-theory

Usage Inference and Decidability

The system provides an algorithmic grading relation, supporting bottom-up inference of the most precise context (principal usage) for a term. Decidability follows by finiteness of grades and contexts (for the common instances) and by design of checking rules.

Substitution, Subject Reduction, and Normalization

The substitution lemma and subject reduction (for both typing and grading) are proved using graded substitutions modeled as matrices (linear maps between contexts), extending fundamental properties of dependent type theories to the resource-aware graded setting. All fundamental meta-theorems, including normalization and decidable equality, are fully mechanized in Agda (by extending prior formalizations [DBLP:journals/pacmpl/0001OV18]).

Extraction and Erasure Soundness

A parameterized extraction function (â‹…\cdot6) compiles to erasure-aware untyped â‹…\cdot7-calculus, with rules varying for strict/non-strict (CBV/CBN) target semantics. Strong invariants are established:

  • Completeness: Every variable with grade 0 is absent from the extracted code.
  • Soundness: For closed terms of base types (â‹…\cdot8), execution (i.e., reduction to numeral) is preserved post-erasure.
  • Open Terms: Soundness holds for open terms under erasable (zero-typed) contexts, provided the context is consistent and erased matches are suitably restricted.

A nontrivial logical relations argument (syntactic Kripke logical relation, formalized in Agda) is employed, proving value- and reduction-preservation under erasure for all supported modalities satisfying the 'well-behaved zero' constraints.

System Extensions and Additional Contributions

Graded â‹…\cdot9-Types and Modes

The system supports graded M={0,ω}\mathcal{M} = \{0, \omega\}0-types with first components at (possibly erasable) grades, enabling erased fields in records. To handle resource safety, modes (present/erased) are introduced; e.g., projections from erased first components are restricted to erased context. The semantics extends Atkey-style tensor products and allows fine-grained control analogous to dependent tuples with mixed resource requirements.

Weak/Strong Unit Types

Both the multiplicative and additive unit types (from linear logic) are included, with corresponding eliminators/rules, and the system allows flexibility in their resource behavior (e.g., strong units being usable in arbitrary context).

Information Flow and Security Typing

The generality of the modality framework enables the system to encode and enforce multi-level information flow policies (e.g., secrecy, clearance) using lattice-based modalities. Noninterference is supported as a corollary of the erasure soundness theorem instantiated for security lattices.

Design Decisions and Comparisons

  • Separation of Usage and Typing: Unlike classical QTT or resource-aware systems with paired grade/type contexts, usage is tracked orthogonally to typing, which enables precise resource analysis especially in the presence of dependency in types.
  • Resource Preservation in Types: Usage annotations are permitted in types as well as in terms, a feature necessary (and shown to be sound) for settings with advanced type-level computation (e.g., cubical/univalent settings).
  • Choice of Grading Mechanisms for Recursors: The system generalizes previous approaches to usage in M={0,ω}\mathcal{M} = \{0, \omega\}1-recursion, allowing user-specified combination functions for grade calculation, which increases expressivity and soundness guarantees.
  • Configurability of Erased Matches: The system can enable or restrict erased pattern matching in weak M={0,ω}\mathcal{M} = \{0, \omega\}2 or unit eliminators, highlighting subtle interactions with canonicity and open term soundness.

Strong Numerical and Formal Results

  • The system is mechanized in ~110,000 lines of Agda, representing the largest and most expressive formalization of a graded dependent type theory (with universe and large elimination).
  • Subject reduction, normalization, and decidability of equality are fully formalized for the class of modality structures described.
  • The extraction function is proved sound for any modality with a well-behaved zero, supporting both call-by-name and call-by-value, and for open or closed terms under graded contexts.

Practical and Theoretical Implications

Graded (modal) dependent type theory subsumes a wide range of practical resource policies, providing a robust meta-theoretical foundation for systems such as Agda, Idris, and experimental resource-aware dependently typed languages. These results also facilitate verified program extraction and optimizations (e.g., dead code erasure, safe result-ignoring) and provide extensibility to richer type-theoretic settings (cubical, univalent foundations) and application domains (security, quantum programming).

The formal framework paves the way for future mechanized, sound type-checkers for graded systems, incorporation of type-based constraint solving for automated grade inference, and deeper semantic analysis for advanced type dependency and categorical models.

Conclusion

The paper achieves a substantial advancement in the theory and mechanization of resource-aware dependent type systems, providing a generic, extensible, and fully formalized framework for modalities with strong guarantees. It validates the practical utility and meta-theoretical soundness of erasure, affineness, linearity, and information flow analyses within dependent type theory, and demonstrates how high-level resource properties can be robustly tracked and preserved across compilation and execution. The work sets the stage for future developments in verified compilation, refined program extraction, and type-theoretic models of computation-aware properties.


References: For details on mechanized proofs and theorem statements, see (2603.29716).

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.

Collections

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

Tweets

Sign up for free to view the 1 tweet with 6 likes about this paper.