ABSTRACT
Meta-programs are programs that generate other programs, but in weakly type-safe systems, type-checking a meta-program only establishes its own type safety, and generated programs need additional type-checking after generation. Strong type safety of a meta-program implies type safety of any generated object program, a property with important engineering benefits. Current strongly type-safe systems suffer from expressivity limitations and cannot support many meta-programs found in practice, for example automatic generation of lenses.
To overcome this, we move away from the idea of staged meta-programming. Instead, we use an off-the-shelf dependently-typed language as the meta-language and a relatively standard, intrinsically well-typed representation of the object language. We scale this approach to practical meta-programming, by choosing a high-level, explicitly typed intermediate representation as the object language, rather than a surface programming language. We implement our approach as a library for the Glasgow Haskell Compiler (GHC) and evaluate it on several meta-programs, including a deriveLenses meta-program taken from a real-world Haskell lens library. Our evaluation demonstrates expressivity beyond the state of the art and applicability to real settings, at little cost in terms of code size.
- Thorsten Altenkirch and Conor McBride. 2003. Generic Programming within Dependently Typed Programming. In IFIP TC2 Working Conference on Generic Programming, Schloss Dagstuhl. Kluwer. Google ScholarDigital Library
- Samuel Boutin. 1997. Using Reflection to Build Efficient and Certified Decision Procedures. In Lect. Notes Comput. Sc. LNCS, Vol. 1281. Springer. Google ScholarDigital Library
- Edwin Brady and Kevin Hammond. 2006. A verified staged interpreter is a verified compiler. In GPCE'06. ACM. Google ScholarDigital Library
- Eugene Burmako. 2017. Unification of Compile-Time and Runtime Metaprogramming in Scala. Ph.D. Dissertation. EPFL.Google Scholar
- James Chapman. 2009. Type Theory Should Eat Itself. In LFMTP'09. Electron. Notes Theor. Comput. Sci., Vol. 228. Elsevier. Google ScholarDigital Library
- Chiyan Chen and Hongwei Xi. 2003. Meta-programming Through Typeful Code Representation. In ICFP '03. ACM. Google ScholarDigital Library
- Nils Anders Danielsson. 2007. A formalisation of a dependently typed language as an inductive-recursive family. In TYPES'07. LNCS, Vol. 4502. Springer. Google ScholarDigital Library
- Rowan Davies and Frank Pfenning. 2001. A Modal Analysis of Staged Computation. J. ACM 48, 3 (May 2001). Google ScholarDigital Library
- Dominique Devriese and Frank Piessens. 2013. Typed Syntactic Meta-programming. SIGPLAN Not. 48, 9 (Sept. 2013). Google ScholarDigital Library
- Jason Eckhardt, Roumen Kaiabachev, Emir Pašalić, Kedar Swadi, and Walid Taha. 2005. Implicitly heterogeneous multi-stage programming. In GPCE'05. Springer. Google ScholarDigital Library
- Seth Fogarty, Emir Pašalić, Jeremy Siek, and Walid Taha. 2007. Concoqtion: indexed types now!. In PEPM'07. ACM. Google ScholarDigital Library
- Yuichiro Hanada and Atsushi Igarashi. 2014. On Cross-Stage Persistence in Multi-Stage Programming. In FLOPS'14. LNCS, Vol. 8475. Springer.Google Scholar
- Pepijn Kokke and Wouter Swierstra. 2015. Auto in Agda. In MPC'15. LNCS, Vol. 9129. Springer.Google Scholar
- Geoffrey Mainland. 2007. Why It's Nice to Be Quoted: Quasiquoting for Haskell. In Haskell'07. ACM. Google ScholarDigital Library
- Geoffrey Mainland. 2012. Explicitly heterogeneous metaprogramming with MetaHaskell. In ICFP '12. ACM. Google ScholarDigital Library
- Geoffrey Mainland. 2013. Type-Safe Runtime Code Generation with (Typed) Template Haskell. (2013). https://www.cs.drexel.edu/~mainland/2013/05/31/type-safe-runtime-code-generation-with-typed-template-haskell/Google Scholar
- Conor McBride. 2010. Outrageous but meaningful coincidences: dependent type-safe syntax and evaluation. In WGP'10. ACM. Google ScholarDigital Library
- Adam Megacz. 2014. Generalized Arrows. Ph.D. Dissertation. EECS Department, University of California, Berkeley.Google Scholar
- Aleksandar Nanevski and Frank Pfenning. 2005. Staged computation with names and necessity. J. Funct. Program. 15 (Nov. 2005). Issue 06. Google ScholarDigital Library
- Aleksandar Nanevski, Frank Pfenning, and Brigitte Pientka. 2008. Contextual modal type theory. ACM T. Comput. Log. 9, 3 (2008). Google ScholarDigital Library
- Ulf Norell. 2007. Towards a practical programming language based on dependent type theory. Ph.D. Dissertation. Chalmers University of Technology.Google Scholar
- Russell O'Connor. 2011. Functor is to lens as applicative is to biplate: Introducing multiplate. WGP'11 (2011).Google Scholar
- Emir Pašalić and Nathan Linger. 2004. Meta-programming with typed object-language representations. In GPCE'04. Springer.Google Scholar
- Emir Pasalić, Walid Taha, and Tim Sheard. 2002. Tagless Staged Interpreters for Typed Languages. In ICFP '02. ACM. Google ScholarDigital Library
- Brigitte Pientka and Joshua Dunfield. 2008. Programming with proofs and explicit contexts. In PPDP'08. ACM. Google ScholarDigital Library
- Tim Sheard and Emir Pašalić. 2004. Meta-programming With Built-in Type Equality. In LFMTP'04.Google Scholar
- Tim Sheard and Simon Peyton Jones. 2002. Template meta-programming for Haskell. SIGPLAN Not. 37, 12 (Dec. 2002). Google ScholarDigital Library
- Antonis Stampoulis and Zhong Shao. 2010. VeriML: Typed Computation of Logical Terms Inside a Language with Effects. In ICFP'10. ACM. Google ScholarDigital Library
- Antonis Stampoulis and Zhong Shao. 2012. Static and user-extensible proof checking. In POPL '12. ACM. Google ScholarDigital Library
- Walid Taha and Michael Florentin Nielsen. 2003. Environment Classifiers. In POPL '03. ACM. Google ScholarDigital Library
- Walid Taha and Tim Sheard. 1997. Multi-stage Programming with Explicit Annotations. SIGPLAN Not. 32, 12 (Dec. 1997). Google ScholarDigital Library
- Walid Taha and Tim Sheard. 2000. MetaML and multi-stage programming with explicit annotations. Theoretical Computer Science 248, 1--2 (2000). Google ScholarDigital Library
- Twan van Laarhoven. 2009. CPS based functional references. (2009). http://twanvl.nl/blog/haskell/cps-functional-referencesGoogle Scholar
- Dimitrios Vytiniotis, Simon Peyton Jones, Tom Schrijvers, and Martin Sulzmann. 2011. OutsideIn(X): Modular type inference with local assumptions. J. Funct. Program. 21, april (2011). Google ScholarDigital Library
Index Terms
Expressive and strongly type-safe code generation
Recommendations
Expressive and safe static reflection with MorphJ
PLDI '08Recently, language extensions have been proposed for Java and C# to support pattern-based reflective declaration. These extensions introduce a disciplined form of meta-programming and aspect-oriented programming to mainstream languages: They allow ...
Expressive and safe static reflection with MorphJ
PLDI '08: Proceedings of the 29th ACM SIGPLAN Conference on Programming Language Design and ImplementationRecently, language extensions have been proposed for Java and C# to support pattern-based reflective declaration. These extensions introduce a disciplined form of meta-programming and aspect-oriented programming to mainstream languages: They allow ...
Typed syntactic meta-programming
ICFP '13We present a novel set of meta-programming primitives for use in a dependently-typed functional language. The types of our meta-programs provide strong and precise guarantees about their termination, correctness and completeness. Our system supports ...
Comments