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.
- 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 Scholar
Digital Library
- D. Abrahams and A. Gurtovoy. C++ template metaprogramming: Concepts, tools, and techniques from Boost and beyond. Addison-Wesley, 2004. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- B. Barras and G. Huet. Auto-validation d'un système de preuves avec familles inductives. PhD thesis, Université de Paris 07, 1999.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- E. Bruneton, R. Lenglet, and T. Coupaye. ASM: a code manipulation tool to implement adaptable systems. Adaptable and extensible component systems, 2002.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- C. Chen and H. Xi. Meta-programming through typeful code representation. In International Conference on Functional Programming, pages 275--286. ACM, 2003. Google Scholar
Digital Library
- A. Chlipala. Parametric higher-order abstract syntax for mechanized semantics. In International Conference on Functional Programming, pages 143--156. ACM, 2008. Google Scholar
Digital Library
- A. Chlipala. Ur: statically-typed metaprogramming with type-level record computation. In Programming Languages Design and Implementation, pages 122--133. ACM, 2010. Google Scholar
Digital Library
- A. Chlipala. Certified programming with dependent types. online, 2012. URL http://adam.chlipala.net/cpdt/.Google Scholar
- 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 Scholar
Digital Library
- N. A. Danielsson. Operational semantics using the partiality monad. In International Conference on Functional Programming, pages 127--138. ACM, 2012. Google Scholar
Digital Library
- N. A. Danielsson and many others. The Agda standard library, 2009.Google Scholar
- 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 Scholar
Digital Library
- J. Darcy. JSR 269: Pluggable annotation processing API, 2011. URL http://jcp.org/en/jsr/detail?id=269.Google Scholar
- 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 Scholar
Digital Library
- P. Dybjer. Inductive families. Formal Aspects of Computing, 6 (4): 440--465, 1994.Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- K. Gödel. Über formal unentscheidbare satze der principia mathematica und verwandter systeme i. Monatshefte für Mathematik, 38 (1): 173--198, 1931.Google Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- S. C. Johnson. YACC. UNIX Programmer's Manual, 2b, 1979.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- J. Launchbury and S. Peyton Jones. Lazy functional state threads. In Programming Languages Design and Implementation, page 35. ACM, 1994. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- G. Mainland and G. Morrisett. Nikola: embedding compiled GPU functions in Haskell. In Haskell Symposium, pages 67--78. ACM, 2010. Google Scholar
Digital Library
- S. Marlow. Haskell 2010 language report. online, 2010. URL http://www.haskell.org/onlinereport/haskell2010/.Google Scholar
- P. Martin-Löf. An intuitionistic theory of types. draft, 1972. URL http://cs.ioc.ee/ james/ITT9200/martinlof72.ps.Google Scholar
- C. McBride. Type-preserving renaming and substitution. draft, 2005. URL http://strictlypositive.org/ren-sub.pdf.Google Scholar
- C. McBride. Outrageous but meaningful coincidences: dependent type-safe syntax and evaluation. In Workshop on Generic Programming, pages 1--12. ACM, 2010. Google Scholar
Digital Library
- U. Norell. Towards a practical programming language based on dependent type theory. PhD thesis, Chalmers, 2007.Google Scholar
- Oracle. Java core reflection. online, 1996. URL http://docs.oracle.com/javase/1.5.0/docs/guide/reflection/spec/java-reflectionTOC.doc.html.Google Scholar
- T. Parr and R. Quong. ANTLR: A predicated-LL(k) parser generator. Software: Practice and Experience, 25 (7): 789--810, 1995. Google Scholar
Digital Library
- 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 Scholar
Cross Ref
- B. Pientka and J. Dunfield. Programming with proofs and explicit contexts. In Principles and Practice of Declarative Programming, pages 163--173. ACM, 2008. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- J. Rudolph and P. Thiemann. Mnemonics: type-safe bytecode generation at run time. Higher-Order and Symbolic Computation, 23 (3): 371--407, 2010. Google Scholar
Digital Library
- T. Sheard and S. P. Jones. Template meta-programming for Haskell. In Workshop on Haskell, pages 1--16. ACM, 2002. Google Scholar
Digital Library
- T. Sheard and E. Pasalic. Meta-programming with built-in type equality. In International Workshop on Logical Frameworks and Meta-Languages, 2004.Google Scholar
- 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 Scholar
Digital Library
- A. Stampoulis and Z. Shao. Static and user-extensible proof checking. In Principles of Programming Languages, pages 273--284. ACM, 2012. Google Scholar
Digital Library
- W. Taha and T. Sheard. MetaML and multi-stage programming with explicit annotations. Theoretical Computer Science, 248 (1--2): 211--242, 2000. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- Wikipedia. Gödel's incompleteness theorems, November 2012. URL http://en.wikipedia.org/wiki/Goedels_incompleteness_theorems.Google Scholar
Index Terms
Typed syntactic meta-programming
Recommendations
Intrinsically-typed definitional interpreters for imperative languages
A definitional interpreter defines the semantics of an object language in terms of the (well-known) semantics of a host language, enabling understanding and validation of the semantics through execution. Combining a definitional interpreter with a ...
Typed syntactic meta-programming
ICFP '13: Proceedings of the 18th ACM SIGPLAN international conference on Functional programmingWe 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 ...
Expressive and strongly type-safe code generation
PPDP '17: Proceedings of the 19th International Symposium on Principles and Practice of Declarative ProgrammingMeta-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 ...







Comments