Abstract
We describe the foundation of the metaprogramming language, Mœbius, which supports the generation of polymorphic code and, more importantly, the analysis of polymorphic code via pattern matching.
Mœbius has two main ingredients: 1) we exploit contextual modal types to describe open code together with the context in which it is meaningful. In Mœbius, open code can depend on type and term variables (level 0) whose values are supplied at a later stage, as well as code variables (level 1) that stand for code templates supplied at a later stage. This leads to a multi-level modal lambda-calculus that supports System-F style polymorphism and forms the basis for polymorphic code generation. 2) we extend the multi-level modal lambda-calculus to support pattern matching on code. As pattern matching on polymorphic code may refine polymorphic type variables, we extend our type-theoretic foundation to generate and track typing constraints that arise. We also give an operational semantics and prove type preservation.
Our multi-level modal foundation for Mœbius provides the appropriate abstractions for both generating and pattern matching on open code without committing to a concrete representation of variable binding and contexts. Hence, our work is a step towards building a general type-theoretic foundation for multi-staged metaprogramming that, on the one hand, enforces strong type guarantees and, on the other hand, makes it easy to generate and manipulate code. This will allow us to exploit the full potential of metaprogramming without sacrificing the reliability of and trust in the code we are producing and running.
Supplemental Material
- Abhishek Anand, Simon Boulier, Cyril Cohen, Matthieu Sozeau, and Nicolas Tabareau. 2018. Towards Certified Meta-Programming with Typed Template-Coq. In 9th International Conference Interactive Theorem Proving (ITP’18) (Lecture Notes in Computer Science (LNCS 10895)). Springer, 20–39. https://doi.org/10.1007/978-3-319-94821-8_2 Google Scholar
Cross Ref
- Nick Benton, Chung-Kil Hur, Andrew Kennedy, and Conor McBride. 2012. Strongly Typed Term Representations in Coq. J. Autom. Reasoning, 49, 2 (2012), 141–159. https://doi.org/10.1007/s10817-011-9219-0 Google Scholar
Digital Library
- Mathieu Boespflug and Brigitte Pientka. 2011. Multi-level Contextual Modal Type Theory. In 6th International Workshop on Logical Frameworks and Meta-languages: Theory and Practice (LFMTP’11) (Electronic Proceedings in Theoretical Computer Science (EPTCS), Vol. 71). 29–43. https://doi.org/10.4204/EPTCS.71.3 Google Scholar
Cross Ref
- Matt Brown and Jens Palsberg. 2016. Breaking through the normalization barrier: a self-interpreter for F-Omega. In 43rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL’16). ACM, 5–17. https://doi.org/10.1145/2837614.2837623 Google Scholar
Digital Library
- Chiyan Chen and Hongwei Xi. 2003. Meta-Programming through Typeful Code Representation. In 8th ACM SIGPLAN International Conference on Functional Programming (ICFP’03). 275–286. https://doi.org/10.1145/944746.944730 Google Scholar
Digital Library
- Chiyan Chen and Hongwei Xi. 2005. Meta-programming through Typeful Code Representation. Journal of Functional Programming, 15, 5 (2005), 797–835. https://doi.org/10.1017/S0956796805005617 Google Scholar
Digital Library
- Rowan Davies. 1996. A Temporal-Logic Approach to Binding-Time Analysis. In 11th IEEE Symposium on Logic in Computer Science (LICS). IEEE Computer Society, 184–195. https://doi.org/10.1109/LICS.1996.561317 Google Scholar
Cross Ref
- Rowan Davies and Frank Pfenning. 2001. A modal analysis of staged computation. J. ACM, 48, 3 (2001), 555–604. https://doi.org/10.1145/382780.382785 Google Scholar
Digital Library
- Daniel Gratzer, Jonathan Sterling, and Lars Birkedal. 2019. Implementing a Modal Dependent Type Theory. Proceedings of the ACM on Programming Languages (PACMPL), 3, ICFP (2019), 107:1–107:29. https://doi.org/10.1145/3341711 Google Scholar
Digital Library
- Junyoung Jang, Samuel Gélineau, Stefan Monnier, and Brigitte Pientka. 2021. Moebius: Metaprogramming using Contextual Types – The stage where System F can pattern match on itself (Long Version). arxiv:2111.08099.Google Scholar
- Akira Kawata and Atsushi Igarashi. 2019. A Dependently Typed Multi-stage Calculus. In 17th Asian Symposium on Programming Languages and Systems (APLAS) (Lecture Notes in Computer Science, Vol. 11893). Springer, 53–72. https://doi.org/10.1007/978-3-030-34175-6_4 Google Scholar
Cross Ref
- Ik-Soon Kim, Kwangkeun Yi, and Cristiano Calcagno. 2006. A Polymorphic Modal Type System for Lisp-like Multi-Staged Languages. In 33rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL’06). ACM Press, 257–268. https://doi.org/10.1145/1111037.1111060 Google Scholar
Digital Library
- Oleg Kiselyov, Yukiyoshi Kameyama, and Yuto Sudo. 2016. Refined Environment Classifiers - Type- and Scope-Safe Code Generation with Mutable Cells. In 14th Asian Symposium on Programming Languages and Systems (APLAS’16) (Lecture Notes in Computer Science, Vol. 10017). 271–291. https://doi.org/10.1007/978-3-319-47958-3_15 Google Scholar
Cross Ref
- Dale Miller. 1991. Unification of Simply Typed Lambda-Terms as Logic Programming. In 8th International Logic Programming Conference. MIT Press, 255–269.Google Scholar
- Aleksandar Nanevski, Frank Pfenning, and Brigitte Pientka. 2008. Contextual Modal Type Theory. ACM Trans. Comput. Logic, 9, 3 (2008), June, 1–49. issn:1529-3785 https://doi.org/10.1145/1352582.1352591 Google Scholar
Digital Library
- Lionel Parreaux, Antoine Voizard, Amir Shaikhha, and Christoph E. Koch. 2018. Unifying Analytic and Statically-Typed Quasiquotes. Proceedings of the ACM on Programming Languages (PACMPL), 2, POPL (2018), 13:1–13:33. https://doi.org/10.1145/3158101 Google Scholar
Digital Library
- Brigitte Pientka. 2003. Tabled higher-order logic programming. Ph. D. Dissertation. Department of Computer Science, Carnegie Mellon University. CMU-CS-03-185Google Scholar
- Brigitte Pientka. 2008. A type-theoretic foundation for programming with higher-order abstract syntax and first-class substitutions. In 35th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL’08). ACM Press, 371–382. https://doi.org/10.1145/1328897.1328483 Google Scholar
Digital Library
- Brigitte Pientka, Andreas Abel, Francisco Ferreira, David Thibodeau, and Rebecca Zucchini. 2019. A Type Theory for Defining Logics and Proofs. In 34th IEEE/ ACM Symposium on Logic in Computer Science (LICS’19). IEEE Computer Society, 1–13. https://doi.org/10.1109/LICS.2019.8785683 Google Scholar
Cross Ref
- Brigitte Pientka and Andrew Cave. 2015. Inductive Beluga:Programming Proofs (System Description). In 25th International Conference on Automated Deduction (CADE-25) (Lecture Notes in Computer Science (LNCS 9195)). Springer, 272–281. https://doi.org/10.1007/978-3-319-21401-6_18 Google Scholar
Cross Ref
- Brigitte Pientka and Jana Dunfield. 2008. Programming with proofs and explicit contexts. In ACM SIGPLAN Symposium on Principles and Practice of Declarative Programming (PPDP’08). ACM, 163–173. https://doi.org/10.1145/1389449.1389469 Google Scholar
Digital Library
- Brigitte Pientka and Jana Dunfield. 2010. Beluga: a Framework for Programming and Reasoning with Deductive Systems (System Description). In 5th International Joint Conference on Automated Reasoning (IJCAR’10) (Lecture Notes in Artificial Intelligence (LNAI 6173)). Springer, 15–21. https://doi.org/10.1007/978-3-642-14203-1_2 Google Scholar
Digital Library
- Morten Rhiger. 2012. Staged Computation with Staged Lexical Scope. In 21st European Symposium on Programming Languages and Systems (ESOP’12) (Lecture Notes in Computer Science, Vol. 7211). Springer, 559–578. https://doi.org/10.1007/978-3-642-28869-2_28 Google Scholar
Digital Library
- Tim Sheard and Simon Peyton Jones. 2022. Template Meta-Programming for Haskell. In ACM SIGPLAN Workshop on Haskell (Haskell’02). ACM, 1–16. https://doi.org/10.1145/581690.581691 Google Scholar
Digital Library
- Walid Taha. 2000. A Sound Reduction Semantics for Untyped CBN Multi-stage Computation. Or, the Theory of MetaML is Non-trivial (Extended Abstract). In ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation (PEPM’00). ACM, 34–43. https://doi.org/10.1145/328690.328697 Google Scholar
Digital Library
- Walid Taha and Michael Florentin Nielsen. 2003. Environment Classifiers. In 30th SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL’03). ACM, 26–37. https://doi.org/10.1145/604131.604134 Google Scholar
Digital Library
- Walid Taha and Tim Sheard. 2000. MetaML and Multi-stage Programming with Explicit Annotations. Theoretical Computer Science, 248, 1-2 (2000), Oct., 211–242. issn:0304-3975 https://doi.org/10.1016/S0304-3975(00)00053-0 Google Scholar
Digital Library
- Paul van der Walt and Wouter Swierstra.. 2012. Engineering Proof by Reflection in Agda. In 24th Intern. Symp. on Implementation and Application of Functional Languages (IFL). Springer, 157–173. https://doi.org/10.1007/978-3-642-41582-1_10 Google Scholar
Cross Ref
- Marcos Viera and Alberto Pardo. 2006. A Multi-Stage Language with Intensional Analysis. In 5th International Conference on Generative Programming and Component Engineering (GPCE’06). ACM, 11–20. isbn:1595932372 https://doi.org/10.1145/1173706.1173709 Google Scholar
Digital Library
Index Terms
Mœbius: metaprogramming using contextual types: the stage where system f can pattern match on itself
Recommendations
Type inference, principal typings, and let-polymorphism for first-class mixin modules
Proceedings of the tenth ACM SIGPLAN international conference on Functional programmingA mixin module is a programming abstraction that simultaneously generalizes λ-abstractions, records, and mutually recursive definitions. Although various mixin module type systems have been developed, no one has investigated principal typings or ...
Type inference, principal typings, and let-polymorphism for first-class mixin modules
ICFP '05: Proceedings of the tenth ACM SIGPLAN international conference on Functional programmingA mixin module is a programming abstraction that simultaneously generalizes λ-abstractions, records, and mutually recursive definitions. Although various mixin module type systems have been developed, no one has investigated principal typings or ...
System F with coercion constraints
CSL-LICS '14: Proceedings of the Joint Meeting of the Twenty-Third EACSL Annual Conference on Computer Science Logic (CSL) and the Twenty-Ninth Annual ACM/IEEE Symposium on Logic in Computer Science (LICS)We present a second-order λ-calculus with coercion constraints that generalizes a previous extension of System F with parametric coercion abstractions by allowing multiple but simultaneous type and coercion abstractions, as well as recursive coercions ...






Comments