Saved in:
Bibliographic Details
Main Authors: Lee, Michael, Xie, Ningning, Kiselyov, Oleg, Yallop, Jeremy
Format: Preprint
Published: 2026
Subjects:
Online Access:https://arxiv.org/abs/2601.18793
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866917223980859392
author Lee, Michael
Xie, Ningning
Kiselyov, Oleg
Yallop, Jeremy
author_facet Lee, Michael
Xie, Ningning
Kiselyov, Oleg
Yallop, Jeremy
contents Metaprogramming and effect handlers interact in unexpected, and sometimes undesirable, ways. One example is scope extrusion: the generation of ill-scoped code. Scope extrusion can either be preemptively prevented, via static type systems, or retroactively detected, via dynamic checks. Static type systems exist in theory, but struggle with a range of implementation and usability problems in practice. In contrast, dynamic checks exist in practice (e.g. in MetaOCaml), but are understudied in theory. Designers of metalanguages are thus given little guidance regarding the design and implementation of checks. We present the first formal study of dynamic scope extrusion checks, introducing a calculus ($λ_{\langle\langle\text{op}\rangle\rangle}$) for describing and evaluating checks. Further, we introduce a novel dynamic check $\unicode{x2014}$ the "Cause-for-Concern" check $\unicode{x2014}$ which we prove correct, characterise without reference to its implementation, and argue combines the advantages of existing dynamic checks. Finally, we extend our framework with refined environment classifiers, which statically prevent scope extrusion, and compare their expressivity with the dynamic checks.
format Preprint
id arxiv_https___arxiv_org_abs_2601_18793
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle Handling Scope Checks (Extended Version)
Lee, Michael
Xie, Ningning
Kiselyov, Oleg
Yallop, Jeremy
Programming Languages
Metaprogramming and effect handlers interact in unexpected, and sometimes undesirable, ways. One example is scope extrusion: the generation of ill-scoped code. Scope extrusion can either be preemptively prevented, via static type systems, or retroactively detected, via dynamic checks. Static type systems exist in theory, but struggle with a range of implementation and usability problems in practice. In contrast, dynamic checks exist in practice (e.g. in MetaOCaml), but are understudied in theory. Designers of metalanguages are thus given little guidance regarding the design and implementation of checks. We present the first formal study of dynamic scope extrusion checks, introducing a calculus ($λ_{\langle\langle\text{op}\rangle\rangle}$) for describing and evaluating checks. Further, we introduce a novel dynamic check $\unicode{x2014}$ the "Cause-for-Concern" check $\unicode{x2014}$ which we prove correct, characterise without reference to its implementation, and argue combines the advantages of existing dynamic checks. Finally, we extend our framework with refined environment classifiers, which statically prevent scope extrusion, and compare their expressivity with the dynamic checks.
title Handling Scope Checks (Extended Version)
topic Programming Languages
url https://arxiv.org/abs/2601.18793