Object languages¶
An object language is a language that a QVR module describes and computes with: the lambda calculus whose terms are the meanings of a grammar's derivations, a type language and its typing relation, a logic whose formulas a model scores. QVR states one in up to five declarations, each adding a layer to the one before:
- a binding signature (
syntax Σ), which fixes the terms; - an equational theory (an
equationsblock ofΣ), which fixes when two terms are equal and how a term computes; - judgments (
judgment J), which relate terms by inference rules; - notations (
notation N for Σ), which fix how terms are written and printed; - derived instances (
deriving (...) for Σ.S), generic operations computed from the signature's description.
This chapter states what an object language denotes as a whole and how the layers depend on one another. The pages it links state each layer precisely:
| Layer | Page |
|---|---|
| signatures, terms, and the generated operations | Tree and graph autoencoders §1 |
| equations, rewriting, normalization, saturation | Equations and normalization |
| moded judgments, checking, inference, charts | Judgments |
| productions, reading, hygiene, printing | Notation and quotation |
| descriptions, deriving handlers, naturality | The meta phase and deriving |
The standard library's std.syntax.lambda is a complete instance: a simply typed lambda
calculus with products and a monad, its computation rules as oriented equations, and a paper
notation (λx. f x, ⟨a, b⟩, m >>= λx. n); std.syntax.types adds its typing judgment.
1. The layers and where they run¶
Every layer elaborates to something the checked core can run or the host can decide, and nothing in an object language needs a core construct of its own.
flowchart TB
S["syntax Σ<br/><small>sorts, constructors, binding arities</small>"] --> F["Families Σ.S<br/><small>checked QIEC data with Σ.S.var</small>"]
S --> O["Generated term operations<br/><small>shift, subst, instantiate, occurs, eq, ord, hash, show</small>"]
S --> E["equations<br/><small>oriented rules and laws</small>"]
E --> T["Program.theories<br/><small>rewriting, NbE, e-graphs on the host</small>"]
E --> N["Σ.S.normalize, Σ.S.equal_modulo<br/><small>checked computations, for rules in the supported fragment</small>"]
S --> J["judgment J<br/><small>moded rules over Σ's terms</small>"]
J --> P["Program.judgments<br/><small>checker, inferencer, chart under any semiring</small>"]
J --> L["[lexicon=G]<br/><small>static check of a deduction's logical forms</small>"]
S --> Q["notation N<br/><small>productions over Σ</small>"]
Q --> R["quotations [| ... |]<br/><small>elaborated to constructor trees</small>"]
Q --> W["Σ.S.show<br/><small>printing through open notations</small>"]
F --> D["deriving<br/><small>Eq, Ord, Hash, Show, Fold, Quote, ...</small>"]
class S,E,J,Q qv-input
class F,O,N,R,W,D qv-checked
class T,P,L qv-output
The split between the checked core and the host follows decidability. Everything that is a total
function of a term with a fixed shape of recursion (the structural operations, the normalizer of a
rule set in the supported fragment, a derived instance) is generated as a checked QIEC computation,
so programs, deductions, encoders, and every transpile target use it as ordinary code. A procedure
that searches (equality saturation, normalization by evaluation over a typing judgment, derivation
search with unification) runs on the host, through
SignatureTheory and
JudgmentSystem, and reports its result
with the evidence it found.
2. Terms¶
A binding signature \(\Sigma\) declares sorts and constructors, and each argument of a constructor
has its own binding arity: the variables, each with a sort, that are in scope in that argument
and nowhere else. Let : Term, (x : Term).Term -> Term binds x in its second argument only. A
bound variable may be annotated by an earlier labeled argument of the same constructor,
Lam : (ty : Type), (x : Term : ty).Term -> Term, which records the variable's type in the term.
This is the many-sorted second-order abstract syntax of Fiore, Plotkin, and Turi
(Fiore et al., 1999; Fiore and Hur, 2010): the terms of \(\Sigma\) in a context \(\Gamma\) form a
presheaf over contexts, and the terms as a whole are the
initial algebra of the
signature's endofunctor, so a definition by structural recursion that respects variables has
exactly one solution.
Terms are stored in de Bruijn form (de Bruijn, 1972). Alpha-equivalent terms are thus
the same value, and alpha-equality, hashing, and ordering are structural. Renaming and
substitution are defined once for every signature by recursion on the binding arities, as in
Autosubst (Stark et al., 2019); the compiler generates them per sort as checked computations
(Σ.S.shift, Σ.S.subst.V, Σ.S.instantiate.V, Σ.S.occurs), together with the structural
Σ.S.eq, Σ.S.ord, and Σ.S.hash, and Σ.S.show, which prints with fresh names. Each generated
operation agrees with its host counterpart in
quivers.structural.binding on every term, which the test suite checks
differentially (structural §1.2.1).
The terms of each object sort are an ordinary checked family Σ.S, whose constructors are the
signature's constructors into S and the variable constructor Σ.S.var(i). This is the decision
that makes an object language usable from the rest of QVR: a program samples terms, a deduction's
logical forms are terms, a case analyzes them with the exhaustiveness check of any family, and an
encoder folds them, with no conversion at any boundary.
3. Equality¶
An equations block turns \(T_\Sigma\) into the terms of an
equational theory: two terms are equal when the
equations prove them equal. Its oriented rules l ~> r and laws l = r are second-order
equations, whose metavariables may be applied to bound variables (App(Lam(x. M[x]), N) ~> M[N])
(Fiore and Mahmoud, 2010). The theory is decided by three procedures, each chosen by the shape of the
equations it serves, never by constructor names (equations):
- Rewriting decides the oriented rules. A left side must be a Miller pattern (Miller, 1991), so matching has at most one solution and the rules form a higher-order pattern rewrite system (Mayr and Nipkow, 1998). Termination is proved by a recursive path order (Dershowitz, 1982) or recorded as assumed, and every critical pair, computed by higher-order pattern unification, must join. A terminating system whose critical pairs all join is confluent, so its normal forms decide its equational theory (Hamana, 2017). A non-joining pair is refused with its peak and both normal forms.
- Normalization by evaluation decides the type-directed laws (eta, surjective pairing, the
monad laws) over the typing judgment
[typing=J]names [@berger1991inverse; @filinski2001normalization]. - Equality saturation in a slotted e-graph decides the remaining laws that rename without substituting, such as commutativity under binders (Willsey et al., 2021; Schneider et al., 2025).
The rewriting strategy is a property of the theory's use, not of its meaning. Under a confluent
terminating system, innermost, outermost, and nodewise reach the same normal form; they
differ in the work done. The nodewise strategy normalizes each node as it is built from
normalized arguments, which suits a term assembled bottom up, such as the meaning of a derivation
built on a chart: no unreduced meaning is ever stored.
The status of each property is recorded, not presumed. Termination and confluence are
Proved when the checks establish them and
Assumed when the block declares assume terminating; a
non-terminating system declared terminating may then loop, and the host normalizer raises
RewriteLimitExceeded at its step bound.
4. Relations between terms¶
A judgment \(J(a_1 : S_1\ m_1, \ldots, a_n : S_n\ m_n)\) is a relation between terms of \(\Sigma\), presented by inference rules whose premises and conclusions are second-order patterns, with a mode \(m_i \in \{\mathtt{in}, \mathtt{out}\}\) for each argument (Dunfield and Krishnaswami, 2021). Its denotation is the least relation closed under the rules, and the declaration gives that relation three readings (judgments):
- as a procedure, when the modes check: the inputs determine the outputs by a syntax-directed search with higher-order pattern unification, which checks a typing and infers a type;
- as a weighted deduction over the judgment's instances, so the same rules run on the chart
under any semiring, the Boolean semiring giving derivability and the log semiring a
distribution over typings when rules carry
#[weight=w]; - as a static check: with
[lexicon=G], every logical form of the deductionGmust have a typing in the empty context, orqvr checkfails at the entry.
The second reading is what joins object languages to the rest of the deduction machinery: a typing
relation is not a separate engine but one more deduction, evaluated by the agenda engine that runs
grammars (weighted deduction). A lexicon's semantics Ty reuses the third reading:
every written or synthesized meaning must have a typing in Ty
(lexicons §5).
5. Concrete syntax¶
A notation is a set of productions over \(\Sigma\), each a shape of tokens and holes with a template
term, ordered by a precedence graph. A quotation [| λx. f x |] denotes the unique term of the
sort it is checked at that the active productions read it as; no reading, or two, is refused with
the productions involved (notation). Reading never changes the grammar: the parser
reads a quotation as a token tree, and its structure comes from the notations active where it
stands.
The term a quotation denotes is a constructor tree of \(\Sigma\) in de Bruijn form, so a quotation is
a value of Σ.S like any other, and two quotations that differ by a renaming of bound names are
one value. Names introduced by a production and names written by the author are kept apart by sets
of scopes (Flatt, 2016), so a notation cannot capture an author's variable. Printing
inverts reading: Σ.S.show is generated from the notations the root module opens, and reading a
printed term gives the term back.
Notation is scoped to modules. open notation N activates N for the rest of the opening module
only, so a module never changes how another module's quotations read.
6. Generic operations¶
A family's description is the code of the polynomial functor whose initial algebra the family is
(Chapman et al., 2010). The signature sorts Σ.S are meta-phase families, so their descriptions
are available to deriving handlers, which compute instances (Eq, Ord, Hash, Show, Fold,
Quote[T via q], Arbitrary) as meta computations over descriptions
(meta). For a syntax sort, a derived Show calls
Σ.S.show and so prints through the open notations, and a derived Hash calls Σ.S.hash.
Quote[T via q] deserves a word, since it connects object languages to grammars. A signature
morphism \(q\) assigns each constructor of a family a term of \(T\), and the derived quote is the
catamorphism with that algebra, so it is the unique structure-preserving map. Reifying a
deduction's items as terms of an object language is thus a fold determined by its clauses, and the
uniqueness of folds gives the naturality law along every deduction extension that keeps the
clauses (composable deductions §6).
7. Object languages across modules¶
export syntax, export judgment, and export notation make each layer a public name, so an
object language may be split across modules and composed by import: std.syntax.lambda declares
the terms, equations, and notation, and std.syntax.types imports it and declares the unification
of its types and its typing judgment. The layers keep their origin when imported, as every declaration does
(module calculus §7), so two
modules that import one syntax share its families and its generated operations, and a term built
by one is a value of the other's family.
A binding signature is not a theory in the sense of the theory layer, and the two
are kept apart by design. A theory is a generalized algebraic theory, whose operations bind no
variables and whose models are finite interpretations; a syntax has binders and its equations
are decided by the rewriting, evaluation, and saturation procedures above. A theory describes
structures that many modules may realize; a syntax describes one language whose terms are data.
8. Guarantees and limits¶
The object-language layer guarantees:
- Alpha-invariance. Every operation on terms (equality, hashing, ordering, normalization, printing, quotation, derived instances) respects alpha-equivalence, because terms are stored without bound names.
- Sound equality. Every procedure reports two terms equal only when the equations prove them equal; rewriting is also complete for a confluent terminating rule set, and normalization by evaluation for the type-directed structures it recognizes.
- Recorded assumptions. An unproved termination claim, and the confluence that rests on it, are recorded as assumed in the law registry, never as proved.
- Agreement. Each generated checked computation agrees with its host counterpart, which the test suite checks differentially.
The limits are those of the procedures. Equality saturation stops at a limit, so a pair it cannot relate is reported unequal, and the theory is not complete once saturation laws are present. Higher-order unification outside the pattern fragment is refused rather than approximated. A judgment's search is complete only when it terminates, which holds for syntax-directed rules; a search that is not bounded by its inputs stops at a depth bound and reports it. And the checked normalizer is generated only for rule sets in the supported fragment, so a theory outside it is decided on the host alone.
Cited sources¶
Marcelo Fiore, Gordon Plotkin, and Daniele Turi. Abstract Syntax and Variable Binding. In Proceedings of the 14th Symposium on Logic in Computer Science (LICS), 193–202. IEEE Computer Society, 1999. doi:10.1109/LICS.1999.782615.
Marcelo Fiore and Chung-Kil Hur. Second-Order Equational Logic (Extended Abstract). In Computer Science Logic (CSL 2010), volume 6247 of Lecture Notes in Computer Science, 320–335. Springer, 2010. doi:10.1007/978-3-642-15205-4_26.
N. G. de Bruijn. Lambda Calculus Notation with Nameless Dummies, a Tool for Automatic Formula Manipulation, with Application to the Church-Rosser Theorem. Indagationes Mathematicae (Proceedings), 75(5):381–392, 1972. doi:10.1016/1385-7258(72)90034-0.
Kathrin Stark, Steven Schäfer, and Jonas Kaiser. Autosubst 2: Reasoning with Multi-Sorted de Bruijn Terms and Vector Substitutions. In Proceedings of the 8th ACM SIGPLAN International Conference on Certified Programs and Proofs, 166–180. ACM, 2019. doi:10.1145/3293880.3294101.
Marcelo Fiore and Ola Mahmoud. Second-Order Algebraic Theories. In Mathematical Foundations of Computer Science (MFCS 2010), volume 6281 of Lecture Notes in Computer Science, 368–380. Springer, 2010. doi:10.1007/978-3-642-15155-2_33.
Dale Miller. A Logic Programming Language with Lambda-Abstraction, Function Variables, and Simple Unification. Journal of Logic and Computation, 1(4):497–536, 1991. doi:10.1093/logcom/1.4.497.
Richard Mayr and Tobias Nipkow. Higher-Order Rewrite Systems and Their Confluence. Theoretical Computer Science, 192(1):3–29, 1998. doi:10.1016/S0304-3975(97)00143-6.
Nachum Dershowitz. Orderings for Term-Rewriting Systems. Theoretical Computer Science, 17(3):279–301, 1982. doi:10.1016/0304-3975(82)90026-3.
Makoto Hamana. How to Prove Your Calculus Is Decidable: Practical Applications of Second-Order Algebraic Theories and Computation. Proceedings of the ACM on Programming Languages, 1(ICFP):1–28, 2017. doi:10.1145/3110266.
Max Willsey, Chandrakana Nandi, Yisu Remy Wang, Oliver Flatt, Zachary Tatlock, and Pavel Panchekha. egg: Fast and Extensible Equality Saturation. Proceedings of the ACM on Programming Languages, 5(POPL):1–29, 2021. doi:10.1145/3434304.
Rudi Schneider, Marcus Rossel, Amir Shaikhha, Andrés Goens, Thomas Kœhler, and Michel Steuwer. Slotted E-Graphs: First-Class Support for (Bound) Variables in E-Graphs. Proceedings of the ACM on Programming Languages, 9(PLDI):1888–1910, 2025. doi:10.1145/3729326.
Jana Dunfield and Neel Krishnaswami. Bidirectional Typing. ACM Computing Surveys, 54(5):98:1–98:38, 2021. doi:10.1145/3450952.
Matthew Flatt. Binding as Sets of Scopes. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 705–717. 2016. doi:10.1145/2837614.2837620.
James Chapman, Pierre-Évariste Dagand, Conor McBride, and Peter Morris. The Gentle Art of Levitation. In Proceedings of the 15th ACM SIGPLAN International Conference on Functional Programming, 3–14. 2010. doi:10.1145/1863543.1863547.