skip to main content
10.1145/3131851.3131872acmotherconferencesArticle/Chapter ViewAbstractPublication PagesppdpConference Proceedingsconference-collections
research-article

Expressive and strongly type-safe code generation

Published:09 October 2017Publication History

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.

References

  1. Thorsten Altenkirch and Conor McBride. 2003. Generic Programming within Dependently Typed Programming. In IFIP TC2 Working Conference on Generic Programming, Schloss Dagstuhl. Kluwer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Samuel Boutin. 1997. Using Reflection to Build Efficient and Certified Decision Procedures. In Lect. Notes Comput. Sc. LNCS, Vol. 1281. Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Edwin Brady and Kevin Hammond. 2006. A verified staged interpreter is a verified compiler. In GPCE'06. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Eugene Burmako. 2017. Unification of Compile-Time and Runtime Metaprogramming in Scala. Ph.D. Dissertation. EPFL.Google ScholarGoogle Scholar
  5. James Chapman. 2009. Type Theory Should Eat Itself. In LFMTP'09. Electron. Notes Theor. Comput. Sci., Vol. 228. Elsevier. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Chiyan Chen and Hongwei Xi. 2003. Meta-programming Through Typeful Code Representation. In ICFP '03. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Nils Anders Danielsson. 2007. A formalisation of a dependently typed language as an inductive-recursive family. In TYPES'07. LNCS, Vol. 4502. Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Rowan Davies and Frank Pfenning. 2001. A Modal Analysis of Staged Computation. J. ACM 48, 3 (May 2001). Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Dominique Devriese and Frank Piessens. 2013. Typed Syntactic Meta-programming. SIGPLAN Not. 48, 9 (Sept. 2013). Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Jason Eckhardt, Roumen Kaiabachev, Emir Pašalić, Kedar Swadi, and Walid Taha. 2005. Implicitly heterogeneous multi-stage programming. In GPCE'05. Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Seth Fogarty, Emir Pašalić, Jeremy Siek, and Walid Taha. 2007. Concoqtion: indexed types now!. In PEPM'07. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Yuichiro Hanada and Atsushi Igarashi. 2014. On Cross-Stage Persistence in Multi-Stage Programming. In FLOPS'14. LNCS, Vol. 8475. Springer.Google ScholarGoogle Scholar
  13. Pepijn Kokke and Wouter Swierstra. 2015. Auto in Agda. In MPC'15. LNCS, Vol. 9129. Springer.Google ScholarGoogle Scholar
  14. Geoffrey Mainland. 2007. Why It's Nice to Be Quoted: Quasiquoting for Haskell. In Haskell'07. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Geoffrey Mainland. 2012. Explicitly heterogeneous metaprogramming with MetaHaskell. In ICFP '12. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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 ScholarGoogle Scholar
  17. Conor McBride. 2010. Outrageous but meaningful coincidences: dependent type-safe syntax and evaluation. In WGP'10. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Adam Megacz. 2014. Generalized Arrows. Ph.D. Dissertation. EECS Department, University of California, Berkeley.Google ScholarGoogle Scholar
  19. Aleksandar Nanevski and Frank Pfenning. 2005. Staged computation with names and necessity. J. Funct. Program. 15 (Nov. 2005). Issue 06. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Aleksandar Nanevski, Frank Pfenning, and Brigitte Pientka. 2008. Contextual modal type theory. ACM T. Comput. Log. 9, 3 (2008). Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Ulf Norell. 2007. Towards a practical programming language based on dependent type theory. Ph.D. Dissertation. Chalmers University of Technology.Google ScholarGoogle Scholar
  22. Russell O'Connor. 2011. Functor is to lens as applicative is to biplate: Introducing multiplate. WGP'11 (2011).Google ScholarGoogle Scholar
  23. Emir Pašalić and Nathan Linger. 2004. Meta-programming with typed object-language representations. In GPCE'04. Springer.Google ScholarGoogle Scholar
  24. Emir Pasalić, Walid Taha, and Tim Sheard. 2002. Tagless Staged Interpreters for Typed Languages. In ICFP '02. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Brigitte Pientka and Joshua Dunfield. 2008. Programming with proofs and explicit contexts. In PPDP'08. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Tim Sheard and Emir Pašalić. 2004. Meta-programming With Built-in Type Equality. In LFMTP'04.Google ScholarGoogle Scholar
  27. Tim Sheard and Simon Peyton Jones. 2002. Template meta-programming for Haskell. SIGPLAN Not. 37, 12 (Dec. 2002). Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Antonis Stampoulis and Zhong Shao. 2010. VeriML: Typed Computation of Logical Terms Inside a Language with Effects. In ICFP'10. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Antonis Stampoulis and Zhong Shao. 2012. Static and user-extensible proof checking. In POPL '12. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Walid Taha and Michael Florentin Nielsen. 2003. Environment Classifiers. In POPL '03. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Walid Taha and Tim Sheard. 1997. Multi-stage Programming with Explicit Annotations. SIGPLAN Not. 32, 12 (Dec. 1997). Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Walid Taha and Tim Sheard. 2000. MetaML and multi-stage programming with explicit annotations. Theoretical Computer Science 248, 1--2 (2000). Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Twan van Laarhoven. 2009. CPS based functional references. (2009). http://twanvl.nl/blog/haskell/cps-functional-referencesGoogle ScholarGoogle Scholar
  34. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Expressive and strongly type-safe code generation

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in
        • Published in

          cover image ACM Other conferences
          PPDP '17: Proceedings of the 19th International Symposium on Principles and Practice of Declarative Programming
          October 2017
          436 pages
          ISBN:9781450352918
          DOI:10.1145/3131851

          Copyright © 2017 ACM

          Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 9 October 2017

          Permissions

          Request permissions about this article.

          Request Permissions

          Check for updates

          Qualifiers

          • research-article

          Acceptance Rates

          PPDP '17 Paper Acceptance Rate18of28submissions,64%Overall Acceptance Rate230of486submissions,47%

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader