Met: F-style Core Calculus for Multimodal Systems
- Met is a rigorous F-style core calculus that underpins multimodal type theory and multi-staged metaprogramming with polymorphism.
- It integrates dependent types, modal operators, and advanced constructs like normalization and decidable type checking to ensure robust type safety.
- The system supports open-code pattern matching and staged computation, forming the backbone for modern polymorphic metaprogramming languages.
The Multimodal System F-style Core Calculus, denoted Met, is a formal system that serves as the foundation for multimodal type theory and multi-staged metaprogramming with polymorphism. It is parameterized by a strict 2-category of modes and supports the construction and analysis of code involving dependent types, modalities, and pattern matching on open polymorphic code. Met accommodates advanced features such as dependent products and sums, universes, intensional identity types, and modal operators, while guaranteeing properties like normalization, decidable type checking, and injectivity of type constructors (Gratzer, 2021, Jang et al., 2021).
1. Modes, Contexts, and Abstract Syntax
Met is built upon a mode theory formalized as a strict 2-category $\Mode$ whose objects are modes (), 1-cells are modalities (), and 2-cells () provide coherence substitutions. Contexts are parameterized by a mode, with formation rules distinguishing between empty contexts $(\cdot \ctx_m)$, locked contexts $(\LockCx{\Gamma}{\mu} \ctx_m)$, and context extension $(\ECx{\Gamma}{A}<\mu> \ctx_m)$. Types include the dependent products (), dependent sums (), booleans 0, a cumulative universe 1, intensional identity types (2), and modal types (3) which transfer types across modes.
Terms incorporate standard lambda calculus constructs with additional modal introduction forms 4 and elimination 5 aligned to the modal structure of the system. The syntax is sufficiently rich to express open code with polymorphic dependencies and manipulable quotations, essential for advanced metaprogramming tasks (Gratzer, 2021, Jang et al., 2021).
2. Declarative Typing and Equality Judgments
Typing in Met is formulated via four principal judgments, all annotated by modes:
- Context formation: 6
- Type formation: 7
- Term formation: 8
- Type and term equality: 9, 0
Type formers are governed by their respective introduction and elimination rules, e.g., dependent products and sums require context extension, while modal types 1 utilize locked contexts. Universe codes are introduced with definitional isomorphisms (2) and modal types commute with universes.
Modalities are equipped with functoriality and coherence equations reflecting the 2-cell structure and guarantee correct inter-mode transport of variables and values. The system is structured to statically ensure correct relationships between terms, their contexts, and corresponding modes (Gratzer, 2021).
3. Judgmental Equality, Beta Laws, and Commuting Conversions
Each type constructor in Met is endowed with corresponding 3-reduction and, for positive types, 4-expansion rules:
- 5, 6 types admit both 7 and 8; e.g. 9, 0.
- 1 supports classical recursion equations.
- Intensional identity has its 2 rule, e.g., 3.
- Modal types 4 have only the 5 rule, such as 6; no 7-law applies.
Commuting conversions (ψ-rules) systematically guarantee compatibility of nested eliminations, such as pushing a modal let-construction through projections or conditionals. Structural rules (reflexivity, symmetry, congruence) complete the definitional equality infrastructure, reducing the conversion problem to syntactic equality of unique normal forms (Gratzer, 2021).
4. Normalization and Synthetic Tait Computability
Normalization in Met states that every well-typed term (and type) admits a unique normal form up to definitional equality:
- Each 8 and 9 has a unique normal form 0 and 1, with 2, 3.
The proof leverages Synthetic Tait Computability: isolating the subcategory of renaming substitutions (4), constructing presheaf topoi, and gluing along the nerve functor to form a normalization model of Met. This model, internal to the glued topos, encodes open/closed modalities and the relationship between neutral terms, normal forms, and all terms via computability predicates and reflection/reification operations.
The normalization function 5 from syntax to normal forms is established through the universal property of the syntactic Met-cosmos, ensuring the uniqueness and definitional stability of normalized representatives (Gratzer, 2021).
5. Decidability and Injectivity Corollaries
Normalization yields two significant corollaries:
- Decidable conversion and type checking: Since reduction to normal forms is terminating and those forms are unique, a terminating algorithm suffices for checking definitional equality. With decidable equality in the mode theory, type checking for Met is also decidable (Gratzer, 2021).
- Injectivity of type constructors: Normalization ensures that, for example, equality of two dependent products implies equality of their domains and codomains; i.e., 6 implies 7 and 8 (and similarly for other positive types and modal codes).
These results underpin robust type-safe manipulation and meta-theoretic properties of systems built upon Met.
6. Role in Multistage Metaprogramming and Pattern Matching
The Met calculus is foundational for advances in metaprogramming languages, such as Moebius, which instrumentalize its modal and polymorphic capabilities. It supports:
- System F-style polymorphic code generation (with 9-introduction and elimination).
- Multi-level quotation and unquotation, tracking open code and contexts at multiple stages or modal levels.
- Intensional pattern matching on open, polymorphic code, with constraint generation and refinement of polymorphic type variables via unification. This allows code to be constructed, analyzed, and deconstructed generically, critical for metaprogramming scenarios.
Decidable unification in the higher-order pattern fragment enables tractable type inference and constraint solving for code templates and open terms, with soundness and subject reduction properties holding across all operations (Jang et al., 2021).
7. Metatheoretic Properties and Impact
Met enjoys foundational metatheoretic properties such as subject reduction, substitution lemmas (for terms, types, and simultaneous substitutions), and unification soundness. The formalism provides a general, type-theoretic foundation for multi-stage metaprogramming and the manipulation of open code templates, meeting both program generation and code analysis requirements in a strongly-typed setting (Jang et al., 2021).
Through its integration of mode theory, normalization, and modal-dependent types, Met delivers a structurally robust and semantically coherent infrastructure for both theoretical exploration and concrete implementation of modern polymorphic, staged, and modal programming languages. Its results on decidability and injectivity position it as a critical foundation for subsequent developments in multimodal type systems and metaprogramming frameworks (Gratzer, 2021, Jang et al., 2021).