Bidirectional Elaborators à la Carte

2026-07-10Programming Languages

Programming LanguagesLogic in Computer Science
AI summary

The authors address the complex process of elaboration in proof assistants, which turns user-friendly syntax into precise, core mathematical code. They create a special programming language that helps specify these elaboration algorithms so they are guaranteed to be correct and stable. Their method uses logic from Martin-Löf type theory and lets them translate surface code into core code without errors. This work also provides a new way to understand elaboration problems mathematically and extracts a working elaboration algorithm from their theoretical framework.

elaborationproof assistantsMartin-Löf type theorydependently typed programmingjudgemental equalitytype constructorsmonadic domain specific languageconversion checkingweak-head reductionpresheaf model
Authors
Andrew Slattery, Jonathan Sterling
Abstract
Surface syntax in proof assistants like Rocq, Lean, Agda, and Idris is highly implicit, lacking many details that are needed for user-written code to denote precisely defined mathematical objects. Elaboration is an algorithm that accounts for these details by translating surface syntax to an explicit enough core syntax. The reliability and predictability of elaboration relies on several critical properties of the core type system, including decidability of judgemental equality and the injectivity of type constructors; these dependencies are witnessed in a concrete system by explicit calls to conversion checking and weak-head reduction subroutines. We introduce a dependently typed monadic domain specific language for the executable specification of correct-by-construction elaboration algorithms that is abstracted from any particular representation of normal forms or algorithm for conversion checking. In particular, we represent a bidirectionally typed surface language for Martin-Löf type theory by shallow embedding in this DSL so that the translation of surface terms into core terms amounts to elementary equational calculation. This translation is correct by construction in the sense that it cannot produce ill-typed terms, and is automatically stable under judgemental equality of core terms and even under substitution; from the latter property, we obtain a new denotational interpretation of the suspension of elaboration problems. Finally, a concrete elaboration algorithm is extracted by algebraic means from a presheaf model of the DSL built out of the bi-initial natural model of Martin-Löf type theory.