
A General Approach to Define Binders Using Matching Logic
Abstract
This paper, authored by Xiaohong Chen and Grigore Rosu and published at ICFP 2020, proposes a novel and general approach to defining binders using matching logic. In programming languages and logical systems, binders are constructs that introduce bound variables --- examples include in the -calculus, in System F, and in the -calculus. Correctly capturing the binding behavior of such constructs (including -equivalence, capture-avoiding substitution, and freshness) has been a longstanding challenge in formal semantics. The key insight of this paper is that matching logic already contains a built-in binder, the existential quantifier , and that object-level binders can be defined so that their binding behavior is directly inherited from this built-in binder. The authors demonstrate that binders in the -calculus, System F, the -calculus, and pure type systems can all be axiomatically defined in matching logic as notations and logical theories. They prove conservative extension theorems establishing that a sequent or judgment is provable in the original system if and only if it is provable in the corresponding matching logic theory, thus showing that nothing is lost and nothing is gained by moving to matching logic.
Introduction
The problem of formally defining binders is as old as the -calculus itself. When Church introduced the -calculus in the 1930s, he implicitly used conventions about bound variables, -equivalence (renaming of bound variables), and capture-avoiding substitution that have since been made rigorous in numerous ways. The challenge is that naive syntactic representations of binders lead to well-known problems: name clashes during substitution, the need for -renaming, and the distinction between free and bound variables. Over the decades, several approaches have been developed to handle binders formally, including de Bruijn indices (which replace named variables with numeric indices), higher-order abstract syntax (HOAS) (which uses the meta-language's binding to represent object-level binding), nominal logic (which introduces a theory of names and swapping), and locally nameless representations (which use de Bruijn indices for bound variables and names for free variables).
Each of these approaches has trade-offs. De Bruijn indices eliminate -equivalence issues but produce terms that are hard for humans to read. HOAS provides an elegant encoding but limits the ability to inspect the structure of binders. Nominal logic offers a principled treatment of freshness and -equivalence but introduces new logical machinery (name swapping, the freshness relation , and the quantifier). The contribution of this paper is to show that matching logic offers a fundamentally different and arguably more uniform approach: binders need not be added as new primitive constructs; instead, they can be defined as notations whose binding behavior is inherited from matching logic's built-in existential quantifier . This approach requires no new logical infrastructure beyond what matching logic already provides, making it attractive for both theoretical foundations and practical implementations.
Background on Matching Logic
Matching logic is a logic for specifying and reasoning about structure. Its formulas, called patterns, are built from variables, symbols (drawn from a signature ), and logical connectives including the existential quantifier . A pattern is interpreted over a carrier set (the domain of the model), and its semantics is a subset of --- the set of elements that "match" the pattern. This is a departure from classical first-order logic, where formulas evaluate to truth values. In matching logic, the pattern denotes the singleton set when is assigned the value , and a symbol application denotes the set where is the interpretation of as a function on sets (not just elements).
The key logical connectives include (complement), (intersection), (union), and (existential quantification, which unions over all valuations of ). The pattern denotes the empty set and denotes the full carrier set. Crucially, the existential quantifier is a binder: the variable is bound in , and all the standard properties of binding (such as -equivalence and capture-avoiding substitution) hold for by the definition of matching logic. The definedness symbol is defined as and evaluates to if is non-empty, and otherwise. Equality is defined as . The logic has a Hilbert-style proof system that is sound and complete for its models, with rules including modus ponens (from and , derive ), universal generalization (from , derive ), and the Propagation axiom ( for any context ).
Defining Binders as Matching Logic Notations
The central technical contribution of the paper is a method for defining object-level binders as notations in matching logic. The idea is to express a binder (where is the binding construct, is the bound variable, and is the body) as a matching logic pattern that uses the existential quantifier to capture the binding of . Specifically, for the -calculus, the -abstraction is defined as a matching logic notation:
Here, and are symbols in the matching logic signature. The existential quantifier in binds in the pair , and since the binding behavior of is well-defined in matching logic, the binding behavior of is automatically inherited. The pattern can be thought of as representing the equivalence class of pairs modulo renaming of --- exactly the right semantics for -equivalence. This definition ensures that and are logically equivalent in matching logic whenever is fresh, mirroring the standard -equivalence of the -calculus.
The authors demonstrate that this approach scales to more complex binding constructs. For System F, the type-level universal quantifier is similarly defined by using to bind the type variable . For the -calculus, the restriction operator uses to bind the channel name . For pure type systems, which generalize many typed -calculi, the dependent product type is defined using the same pattern of wrapping the bound variable in an existential quantifier. In each case, the binding behavior is inherited from matching logic's built-in binder rather than being postulated as a new primitive.
Conservative Extension Theorems
The main correctness results of the paper are conservative extension theorems for the -calculus, System F, and other systems. These theorems establish a precise correspondence between provability in the original system and provability in the matching logic theory. For the -calculus, the conservative extension theorem states:
A sequent is derivable in the simply-typed -calculus if and only if the corresponding matching logic pattern is provable in the matching logic theory .
This theorem is proved by constructing a faithful translation from -calculus derivations to matching logic proofs (soundness) and from matching logic proofs back to -calculus derivations (completeness). The translation maps each -calculus typing rule to a corresponding derived rule in matching logic. The proof requires careful handling of variable binding, substitution, and the interaction between the object-level and meta-level quantifiers. A similar conservative extension theorem is proved for System F, where type abstraction and type application are defined as matching logic notations, and the typing rules of System F are derived as matching logic theorems.
The significance of these results is that they demonstrate that matching logic does not alter the deductive power of the original systems. A user working in the matching logic theory of the -calculus can prove exactly the same theorems as a user working directly in the -calculus. The matching logic formulation is not a mere encoding; it is a faithful representation that preserves all the reasoning power of the original system while situating it within a uniform logical framework. This uniformity is valuable for frameworks like K, where multiple languages with different binding constructs must coexist within a single formal environment.
Representational Completeness
Beyond deductive completeness (the conservative extension property), the paper establishes a stronger property for the -calculus called representational completeness. A semantics of the -calculus is representationally complete if every closed normal form has a unique syntactic representation. Formally, a model of the -calculus is representationally complete if for every element in the carrier set that is the denotation of some closed normal form, that normal form is uniquely determined. Many existing approaches to -calculus semantics fail to achieve representational completeness. For example, in set-theoretic models, the interpretation of the function space is typically the set of all functions from to , which contains many elements that do not correspond to any -term.
The matching logic semantics achieves representational completeness because patterns in matching logic denote subsets of the carrier set, and the axiomatization of the -calculus in matching logic ensures that distinct normal forms are interpreted as distinct (singleton) subsets. The proof of representational completeness proceeds by constructing a term model (also known as a Henkin model or a syntactic model) in which the carrier set consists of equivalence classes of -terms modulo -equivalence, and showing that this model satisfies all the matching logic axioms for the -calculus. In this model, every element is the denotation of a unique normal form (up to -equivalence), establishing the representational completeness property. This result distinguishes the matching logic approach from many alternatives and provides additional confidence in the faithfulness of the representation.
Application to Multiple Binding Constructs
The paper systematically applies the binder-definition methodology to several binding constructs beyond the basic -abstraction:
- System F (polymorphic -calculus): The type abstraction is defined as , directly mirroring the pattern used for -abstraction but at the type level. The type application and the universal type are defined correspondingly.
- -calculus: The restriction operator , which introduces a new channel name scoped over process , is defined as . The input prefix , which binds in , is defined similarly.
- Pure type systems: The dependent product , where is bound in , is defined as . This definition handles the dependency of on through the existential quantifier.
- Let-bindings and pattern matching: The let expression , where is bound in , follows the same pattern: .
In each case, the conservative extension theorem is established, proving that the matching logic theory faithfully represents the original system. The uniformity of the approach --- always using to capture binding and proving conservative extension by the same methodology --- is a key advantage. It suggests that the approach can be applied to any binding construct in any language or logic, making it a truly general solution to the binder problem.
Conclusion
The paper makes a compelling case that matching logic provides a natural and general foundation for defining binders. By leveraging the built-in existential quantifier as the universal source of binding behavior, the approach avoids the proliferation of ad hoc mechanisms for handling bound variables. The conservative extension theorems provide rigorous correctness guarantees, and the representational completeness result for the -calculus provides additional assurance that the matching logic semantics faithfully captures the intended meaning of binders. The approach has significant practical implications for the K framework, where programming language definitions frequently involve binding constructs (function definitions, let-bindings, for-loops with scoped variables, exception handlers, etc.), and having a uniform treatment of all binders simplifies both the definitions and the verification infrastructure.
The paper also opens several directions for future work, including extending the approach to dependent type theories and homotopy type theory, applying it to language definitions in K that involve complex binding patterns, and exploring the connections between matching logic's treatment of binders and categorical semantics (specifically, presheaf models and functorial semantics). The work represents an important step toward matching logic's goal of serving as a unified foundation for programming languages and formal verification, where all aspects of a language --- from syntax to type systems to operational semantics to program logics --- can be expressed and reasoned about within a single logical framework.
Stay Informed
Sign up for updates and never miss important announcements.
Join the community
Join our Discord server to get support or connect with the Pi² community.