,
Andrzej S. Murawski
,
C.-H. Luke Ong
Creative Commons Attribution 4.0 International license
MetaML-style metaprogramming languages allow programmers to construct, manipulate and run code. In the presence of higher-order references for code, ensuring type safety is challenging, as free variables can escape their binders. In this paper, we present Contextual MetaML, the first metaprogramming language that supports storing and running open code under a strong type safety guarantee. The type system utilises contextual modal types to track and reason about free variables in code explicitly. A crucial concern in metaprogramming-based program optimisations is whether the optimised program preserves the meaning of the original program. Addressing this question requires a notion of program equivalence and techniques to reason about it. In this paper, we provide a semantic model that captures contextual equivalence for Contextual MetaML, establishing the first full abstraction result for an imperative MetaML-style language. Our model is based on traces derived via operational game semantics, where the meaning of a program is modelled by its possible interactions with the environment. We also establish a novel closed instances of use theorem that accounts for both call-by-value and call-by-name closing substitutions.
@InProceedings{yin_et_al:LIPIcs.LICS.2026.83,
author = {Yin, Haoxuan and Murawski, Andrzej S. and Ong, C.-H. Luke},
title = {{Contextual MetaML: Syntax and Full Abstraction}},
booktitle = {41st Annual Symposium on Logic in Computer Science (LICS 2026)},
pages = {83:1--83:27},
series = {Leibniz International Proceedings in Informatics (LIPIcs)},
ISBN = {978-3-95977-434-5},
ISSN = {1868-8969},
year = {2026},
volume = {380},
editor = {Faggian, Claudia and Katoen, Joost-Pieter},
publisher = {Schloss Dagstuhl -- Leibniz-Zentrum f{\"u}r Informatik},
address = {Dagstuhl, Germany},
URL = {https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.LICS.2026.83},
URN = {urn:nbn:de:0030-drops-268708},
doi = {10.4230/LIPIcs.LICS.2026.83},
annote = {Keywords: Metaprogramming, operational game semantics, trace model, contextual modal type theory}
}