Handling Scope Checks: A Comparative Framework for Dynamic Scope Extrusion Checks
Michael Lee, Ningning Xie, Oleg Kiselyov, Jeremy Yallop
Abstract
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 metaprogramming languages 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 (𝜆 ⟨ ⟨op⟩ ⟩ ) for describing and evaluating checks. Further, we introduce a novel dynamic check -the "Cause-for-Concern" check -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.
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
2 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Handling the Selection Monad cites Retrofitting effect handlers onto OCaml
- Mechanised Semantics of Multi-stage Programming cites Staging with class: a specification for typed template Haskell
- Retrofitting effect handlers onto OCaml cites Compiler and runtime support for continuation marks
- Refined² Environment Classifiers cites Mechanised Semantics of Multi-stage Programming
Cited by top-tier papers2
Builds on5
- Retrofitting effect handlers onto OCamlK. C. Sivaramakrishnan, Stephen Dolan, Leo White, Tom Kelly et al.PLDI 2021 · 56 citations
- Staging with class: a specification for typed template HaskellNingning Xie, Matthew Pickering, Andres Löh, Nicolas Wu et al.POPL 2022 · 17 citations
- flap: A Deterministic Parser with Fused LexingJeremy Yallop, Ningning Xie, Neel KrishnaswamiPLDI 2023 · 10 citations
- Compiler and runtime support for continuation marksMatthew Flatt, R. Kent DybvigPLDI 2020 · 9 citations
- Handling the Selection MonadGordon D. Plotkin, Ningning XiePLDI 2025 · 1 citation
Related papers
- A typed continuation-passing translation for lexical effect handlersPhilipp Schuster, Jonathan Immanuel Brachthäuser, Marius Müller, Klaus OstermannPLDI 2022 · 10 citations
- Dynamic Wind for Effect HandlersDavid Voigt, Philipp Schuster, Jonathan Immanuel BrachthäuserOOPSLA 2025
- From Capabilities to Regions: Enabling Efficient Compilation of Lexical Effect HandlersMarius Müller, Philipp Schuster, Jonathan Lindegaard Starup, Klaus Ostermann et al.OOPSLA 2023 · 7 citations
- Modal Effect TypesWenhao Tang, Leo White, Stephen Dolan, Daniel Hillerström et al.OOPSLA 2025 · 4 citations
- When Do Staging Annotations Preserve Semantics? Mechanizing Typed Semantics-Preserving Multi-stage Programming with Let-InsertionJun Tan, Guannan WeiOOPSLA 2026
