An ML-style module system for cross-stage type abstraction in multi-stage programming

We propose MetaFM, a novel ML-style module system that enables users to decompose multi-stage programs (i.e., programs written in a typed multi-stage programming language) into loosely coupled components in a manner natural with respect to type abstraction. The distinctive aspect of MetaFM is that i...

Full description

Saved in:
Bibliographic Details
Published in:Science of computer programming Vol. 248; p. 103379
Main Authors: Suwa, Takashi, Igarashi, Atsushi
Format: Journal Article
Language:English
Published: Elsevier B.V 01.03.2026
Subjects:
ISSN:0167-6423
Online Access:Get full text
Tags: Add Tag
No Tags, Be the first to tag this record!
Description
Summary:We propose MetaFM, a novel ML-style module system that enables users to decompose multi-stage programs (i.e., programs written in a typed multi-stage programming language) into loosely coupled components in a manner natural with respect to type abstraction. The distinctive aspect of MetaFM is that it allows values at different stages to be bound in a single structure (i.e., struct⋯end). This feature is crucial, for example, for defining a function and a macro that use one abstract type in common without revealing the implementation detail of that type. MetaFM also accommodates staging with full-fledged module-related features such as functors, higher-kinded types, and the with type-construct. We give two separate formalizations of MetaFM's semantics by employing the technique of elaborations, i.e., type-directed translations to target languages. Specifically, we first define F-ing Modules-based semantics as a set of elaboration rules that convert MetaFM programs into System Fω〈〉, a multi-stage extension of System Fω, and prove that the elaboration preserves typing. The existential quantification offered by System Fω〈〉 demonstrates that a type abstraction mechanism is properly formalized in our language. Then, because our F-ing Modules-based semantics of staging has some issues as to the evaluation order, we give another elaboration by utilizing a method called static interpretation, which flattens nested structures into arrays of bindings and inlines functor applications through type-checking. While our F-ing Modules-based semantics cannot be naturally extended with effectful computations, the static interpretation-based one can easily accommodate effectful features such as mutable references, though this is achieved with the limitation that functors must be first-order for the moment. As a sideline, we develop a technique that simplifies the correctness proof of the static interpretation for first-order functors. Additionally, our language supports cross-stage persistence (CSP), a feature for code reuse spanning more than one stage, without breaking type safety. We also implemented a module system for a language of real-world use based on the latter semantics to demonstrate the utility of our formalization. •A module system for splitting multi-stage programs without breaking type abstraction.•Gives semantics through F-ing Modules-based elaboration.•Extends System Fω with staging constructs to use it as a target language.•Refines elaboration by using static interpretation to accommodate effectful programs.•Uses a new technique for proving correctness of first-order static interpretation.
ISSN:0167-6423
DOI:10.1016/j.scico.2025.103379