skip to main content
research-article

Typed syntactic meta-programming

Published:25 September 2013Publication History
Skip Abstract Section

Abstract

We 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 type-safe construction and analysis of terms, types and typing contexts. Unlike alternative approaches, they are written in the same style as normal programs and use the language's standard functional computational model. We formalise the new meta-programming primitives, implement them as an extension of Agda, and provide evidence of usefulness by means of two compelling applications in the fields of datatype-generic programming and proof tactics.

References

  1. A. Abel. Irrelevance in type theory with a heterogeneous equality judgement. In Foundations of Software Science and Computational Structures, volume 6604 of Lecture Notes in Computer Science, pages 57--71. Springer, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. D. Abrahams and A. Gurtovoy. C++ template metaprogramming: Concepts, tools, and techniques from Boost and beyond. Addison-Wesley, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. T. Altenkirch and C. McBride. Generic programming within dependently typed programming. In IFIP TC2 Working Conference on Generic Programming, Schloss Dagstuhl, pages 1--20. Kluwer, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. B. Barras and G. Huet. Auto-validation d'un système de preuves avec familles inductives. PhD thesis, Université de Paris 07, 1999.Google ScholarGoogle Scholar
  5. S. Boutin. Using reflection to build efficient and certified decision procedures. In Theoretical Aspects of Computer Software, volume 1281 of Lecture Notes in Computer Science, pages 515--529. Springer, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. E. Brady and K. Hammond. A verified staged interpreter is a verified compiler. In Generative Programming and Component Engineering, pages 111--120. ACM, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. E. C. Brady and K. Hammond. Scrapping your inefficient engine: using partial evaluation to improve domain-specific language implementation. In International Conference on Functional Programming, pages 297--308. ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. E. Bruneton, R. Lenglet, and T. Coupaye. ASM: a code manipulation tool to implement adaptable systems. Adaptable and extensible component systems, 2002.Google ScholarGoogle Scholar
  9. J. Chapman. Type theory should eat itself. In International Workshop on Logical Frameworks and Metalanguages: Theory and Practice, volume 228 of Electronic Notes in Theoretical Computer Science, pages 21--36. Elsevier, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. J. Chapman, P.-E. Dagand, C. McBride, and P. Morris. The gentle art of levitation. In International Conference on Functional Programming, pages 3--14. ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. C. Chen and H. Xi. Meta-programming through typeful code representation. In International Conference on Functional Programming, pages 275--286. ACM, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. A. Chlipala. Parametric higher-order abstract syntax for mechanized semantics. In International Conference on Functional Programming, pages 143--156. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. A. Chlipala. Ur: statically-typed metaprogramming with type-level record computation. In Programming Languages Design and Implementation, pages 122--133. ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. A. Chlipala. Certified programming with dependent types. online, 2012. URL http://adam.chlipala.net/cpdt/.Google ScholarGoogle Scholar
  15. N. A. Danielsson. A formalisation of a dependently typed language as an inductive-recursive family. In Types for Proofs and Programs, volume 4502 of Lecture Notes in Computer Science, pages 93--109. Springer, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. N. A. Danielsson. Operational semantics using the partiality monad. In International Conference on Functional Programming, pages 127--138. ACM, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. N. A. Danielsson and many others. The Agda standard library, 2009.Google ScholarGoogle Scholar
  18. N. A. Danielsson and U. Norell. Parsing mixfix operators. In Implementation and Application of Functional Languages, volume 5836 of Lecture Notes in Computer Science, pages 80--99. Springer, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. J. Darcy. JSR 269: Pluggable annotation processing API, 2011. URL http://jcp.org/en/jsr/detail?id=269.Google ScholarGoogle Scholar
  20. D. Delahaye. A tactic language for the system Coq. In Logic Programming and Automated Reasoning, volume 1955 of Lecture Notes in Artificial Intelligence, pages 85--95. Springer, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. P. Dybjer. Inductive families. Formal Aspects of Computing, 6 (4): 440--465, 1994.Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. P. Dybjer and A. Setzer. A finite axiomatization of inductive-recursive definitions. In Typed Lambda Calculi and Applications, volume 1581 of Lecture Notes in Computer Science, pages 129--146. Springer, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. S. Fogarty, E. Pasalic, J. Siek, and W. Taha. Concoqtion: indexed types now! In Symposium on Partial Evaluation and Semantics-Based Program Manipulation, pages 112--121. ACM, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. K. Gödel. Über formal unentscheidbare satze der principia mathematica und verwandter systeme i. Monatshefte für Mathematik, 38 (1): 173--198, 1931.Google ScholarGoogle ScholarCross RefCross Ref
  25. H. Goguen, C. McBride, and J. McKinna. Eliminating dependent pattern matching. In Algebra, Meaning, and Computation, volume 4060 of Lecture Notes in Computer Science, pages 521--540. Springer, 2006.Google ScholarGoogle ScholarCross RefCross Ref
  26. G. Gonthier, B. Ziliani, A. Nanevski, and D. Dreyer. How to make ad hoc proof automation less ad hoc. In International Conference on Functional Programming, pages 163--175. ACM, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. G. Gonthier, B. Ziliani, A. Nanevski, and D. Dreyer. How to make ad hoc proof automation less ad hoc. technical appendix, 2011. URL http://www.mpi-sws.org/ beta/lessadhoc/appendix.pdf.Google ScholarGoogle Scholar
  28. A. J. C. Hurkens. A simplification of Girard's paradox. In Typed Lambda Calculi and Applications, volume 902 of Lecture Notes in Computer Science, pages 266--278. Springer, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. S. C. Johnson. YACC. UNIX Programmer's Manual, 2b, 1979.Google ScholarGoogle Scholar
  30. O. Kiselyov, C.-c. Shan, D. P. Friedman, and A. Sabry. Backtracking, interleaving, and terminating monad transformers: (functional pearl). In International Conference on Functional Programming, pages 192--203. ACM, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. R. Lammel and S. Peyton-Jones. Scrap your boilerplate: a practical design pattern for generic programming. In Types in Languages Design and Implementation, pages 26--37. ACM, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. J. Launchbury and S. Peyton Jones. Lazy functional state threads. In Programming Languages Design and Implementation, page 35. ACM, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. J. P. Magalhaes, A. Dijkstra, J. Jeuring, and A. Löh. A generic deriving mechanism for Haskell. In Haskell Symposium, pages 37--48. ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. G. Mainland and G. Morrisett. Nikola: embedding compiled GPU functions in Haskell. In Haskell Symposium, pages 67--78. ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. S. Marlow. Haskell 2010 language report. online, 2010. URL http://www.haskell.org/onlinereport/haskell2010/.Google ScholarGoogle Scholar
  36. P. Martin-Löf. An intuitionistic theory of types. draft, 1972. URL http://cs.ioc.ee/ james/ITT9200/martinlof72.ps.Google ScholarGoogle Scholar
  37. C. McBride. Type-preserving renaming and substitution. draft, 2005. URL http://strictlypositive.org/ren-sub.pdf.Google ScholarGoogle Scholar
  38. C. McBride. Outrageous but meaningful coincidences: dependent type-safe syntax and evaluation. In Workshop on Generic Programming, pages 1--12. ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. U. Norell. Towards a practical programming language based on dependent type theory. PhD thesis, Chalmers, 2007.Google ScholarGoogle Scholar
  40. Oracle. Java core reflection. online, 1996. URL http://docs.oracle.com/javase/1.5.0/docs/guide/reflection/spec/java-reflectionTOC.doc.html.Google ScholarGoogle Scholar
  41. T. Parr and R. Quong. ANTLR: A predicated-LL(k) parser generator. Software: Practice and Experience, 25 (7): 789--810, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. E. Pasalić and N. Linger. Meta-programming with typed object-language representations. In Generative Programming and Component Engineering, volume 3286 of Lecture Notes in Computer Science, pages 136--167. Springer, 2004.Google ScholarGoogle ScholarCross RefCross Ref
  43. B. Pientka and J. Dunfield. Programming with proofs and explicit contexts. In Principles and Practice of Declarative Programming, pages 163--173. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. A. Poswolsky and C. Schürmann. Practical programming with higher-order encodings and dependent types. In Programming Languages and Systems, volume 4960 of Lecture Notes in Computer Science, pages 93--107. Springer, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. G. Richards, C. Hammer, B. Burg, and J. Vitek. The eval that men do. In European Conference on Object-Oriented Programming, volume 6813 of Lecture Notes in Computer Science, pages 52--78. Springer, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. A. Rodriguez, S. Holdermans, A. Löh, and J. Jeuring. Generic programming with fixed points for mutually recursive datatypes. In International Conference on Functional Programming, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. J. Rudolph and P. Thiemann. Mnemonics: type-safe bytecode generation at run time. Higher-Order and Symbolic Computation, 23 (3): 371--407, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. T. Sheard and S. P. Jones. Template meta-programming for Haskell. In Workshop on Haskell, pages 1--16. ACM, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. T. Sheard and E. Pasalic. Meta-programming with built-in type equality. In International Workshop on Logical Frameworks and Meta-Languages, 2004.Google ScholarGoogle Scholar
  50. A. Stampoulis and Z. Shao. VeriML: typed computation of logical terms inside a language with effects. In International Conference on Functional Programming, pages 333--344. ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. A. Stampoulis and Z. Shao. Static and user-extensible proof checking. In Principles of Programming Languages, pages 273--284. ACM, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  52. W. Taha and T. Sheard. MetaML and multi-stage programming with explicit annotations. Theoretical Computer Science, 248 (1--2): 211--242, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. S. Tobin-Hochstadt, V. St-Amour, R. Culpepper, M. Flatt, and M. Felleisen. Languages as libraries. In Programming Languages Design and Implementation, pages 132--141. ACM, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  54. Wikipedia. Gödel's incompleteness theorems, November 2012. URL http://en.wikipedia.org/wiki/Goedels_incompleteness_theorems.Google ScholarGoogle Scholar

Index Terms

  1. Typed syntactic meta-programming

          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

          Full Access

          • Published in

            cover image ACM SIGPLAN Notices
            ACM SIGPLAN Notices  Volume 48, Issue 9
            ICFP '13
            September 2013
            457 pages
            ISSN:0362-1340
            EISSN:1558-1160
            DOI:10.1145/2544174
            Issue’s Table of Contents
            • cover image ACM Conferences
              ICFP '13: Proceedings of the 18th ACM SIGPLAN international conference on Functional programming
              September 2013
              484 pages
              ISBN:9781450323260
              DOI:10.1145/2500365

            Copyright © 2013 ACM

            Publisher

            Association for Computing Machinery

            New York, NY, United States

            Publication History

            • Published: 25 September 2013

            Check for updates

            Qualifiers

            • research-article

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader
          About Cookies On This Site

          We use cookies to ensure that we give you the best experience on our website.

          Learn more

          Got it!