A theory: its sorts, its operations, and its equations. This is the
object the category of theories (the sheaf site) will range over.
Constructors
TheorytheorySorts :: [Sort]theoryOps :: [Op]theoryEquations :: [Equation]
:: a typeCtrl KGHC 10.0.0.20260917 · lts/ghc-10.0.x · 8174fa4 · 2026-10-11
Modulesheaf-0.2.0.0GHC2021
A theory as first-class data: the signature of a vortex DSL — its sorts, its operations (each a sorted arity), and the equations its terms satisfy. Pure syntax, no interpretation and no IO: a theory says what can be written, never what it means. A model (an interpreter) is a separate thing an app supplies; see the estate master plan, L4.
This is the L4-P0 skeleton (master-plan G18a): the vocabulary the
category of theories is about, plus a canonical printer and parser
whose round-trip law (parse . print = Right) is this phase's exit
check. Morphisms, pushouts, and the sheaf gluing come later and
build on this datatype; nothing here commits to them.
The representation is deliberately small and self-contained (base +
containers). A later phase reconciles Term with vortex-elab's own
typed-term representation rather than keeping two; until the host
(vortex-theory) exists, this stands alone so the DSL closure the
elaborator will load carries no host code.
A theory: its sorts, its operations, and its equations. This is the
object the category of theories (the sheaf site) will range over.
TheorytheorySorts :: [Sort]theoryOps :: [Op]theoryEquations :: [Equation]A sort: a named carrier the theory ranges over (e.g. Signal,
Mesh, Machine). Just a name at this layer.
An operation: a name, the sorts of its arguments (in order), and the sort of its result. This is a sorted arity — the whole of what the signature says about an op. A nullary op (empty argument list) is a constant of its result sort.
An equation: two terms asserted equal (they must be of the same
sort in a well-formed theory; that is checked, not assumed here),
under premises. With no premises it holds everywhere; with premises it
is a conditional equation (a Horn clause of equational logic), holding
wherever every premise does. A side condition that is a predicate is
stated as a premise p(…) = true over a declared boolean sort, which
keeps premises positive, as Horn clauses require.
A premise of a conditional equation: two terms that must be equal for the equation to hold.
A term over the signature: a variable (its name and sort) or an operation applied to sub-terms. Terms are what equations relate and what a later fold interprets; here they exist so equations can be stated and so the printer/parser have something to round-trip.
An equation that holds everywhere.
An equation that holds wherever its premises do.
Build a theory, canonicalising the sort and op lists (deduplicated and ordered) so two theories that declare the same signature in a different order are equal and print identically. Equations keep their given order (order can be semantically relevant to a later rewrite system, so we do not reorder them — only sorts and ops are sets).
The empty theory: no sorts, no ops, no equations. The initial object of the category; a colimit's identity element.
The declared sort names.
The declared operation names.
Is this sort declared in the theory?
Check well-formedness: every op's argument and result sorts are declared, op names are unique, every term in an equation names a declared op with the right arity, every variable is used at a single sort across a clause, the two sides of each equation and of each of its premises have the same sort, and no op is named like a keyword. Returns the list of problems (empty = well formed).
Ways a theory can fail well-formedness (verification level #1 in the master plan: everything refers only to declared sorts, and equations are sort-consistent). Total and decidable.
OpUsesUndeclaredSort String Sortop name, the undeclared sort
DuplicateOpName Stringtwo ops share a name
EquationVarClash String Sort Sorta var used at two sorts
EquationUsesUnknownOp Stringa term names an undeclared op
EquationArityMismatch String Int Intop, expected, got
EquationSortMismatch Term Sort Sortterm, lhs sort, rhs sort
ReservedOpName Stringan op named like a keyword of the canonical form
Eq WellFormedErrorDefined in sheaf-0.2.0.0 · Sheaf.TheoryShow WellFormedErrorDefined in sheaf-0.2.0.0 · Sheaf.TheoryPrint a theory to its canonical textual form. The form is line
oriented and stable (sorts then ops then equations, each already in
canonical order from theory), so parseTheory . printTheory is the
identity on well-constructed theories — the round-trip law that is
this phase's exit check. This is a human- and diff-friendly
serialisation; it is not the wire protocol (that is vortex-wire).
Parse the canonical form back to a Theory. Deliberately small and
forgiving of surrounding whitespace; it is the inverse of
printTheory on that printer's own output, which is all the exit
check requires. Returns Left with a message on malformed input.