Abstract
Languages with support for metaprogramming, like MetaOCaml, offer a principled approach to code generation by guaranteeing that well-typed metaprograms produce well-typed programs. However, many problem domains where metaprogramming can fruitfully be applied require generating code in languages like C, CUDA, or assembly. Rather than resorting to add-hoc code generation techniques, these applications should be directly supported by explicitly heterogeneous metaprogramming languages.
We present MetaHaskell, an extension of Haskell 98 that provides modular syntactic and type system support for type safe metaprogramming with multiple object languages. Adding a new object language to MetaHaskell requires only minor modifications to the host language to support type-level quantification over object language types and propagation of type equality constraints. We demonstrate the flexibility of our approach through three object languages: a core ML language, a linear variant of the core ML language, and a subset of C. All three languages support metaprogramming with open terms and guarantee that well-typed MetaHaskell programs will only produce closed object terms that are well-typed. The essence of MetaHaskell is captured in a type system for a simplified metalanguage. MetaHaskell, as well as all three object languages, are fully implemented in the mhc bytecode compiler.
- Robert Atkey, Sam Lindley, and Jeremy Yallop. Unembedding domain-specific languages. In Proceedings of the 2nd ACM SIGPLAN Symposium on Haskell (Haskell '09), pages 37--48, Edinburgh, Scotland, 2009. ACM. Google Scholar
Digital Library
- Franz Baader and Tobias Nipkow. Term Rewriting and All That. Cambridge University Press, 1998. Google Scholar
Digital Library
- Gershom Bazerman. jmacro, jul 2011.Google Scholar
- Cristiano Calcagno, Eugenio Moggi, and Tim Sheard. Closed types for a safe imperative MetaML. Journal of Functional Programming, 13 (03): 545--571, 2003. Google Scholar
Digital Library
- Cristiano Calcagno, Eugenio Moggi, and Walid Taha. ML-Like inference for classifiers. In In European Symposium on Programming (ESOP '04), volume 2986 of Lecture Notes in Computer Science, pages 79--93, 2004.Google Scholar
Cross Ref
- Jacques Carette. Gaussian elimination: A case study in efficient genericity with MetaOCaml. Science of Computer Programming, 62 (1): 3--24, sep 2006. Google Scholar
Digital Library
- P. P. Chang and W.-W. Hwu. Inline function expansion for compiling c programs. In Proceedings of the ACM SIGPLAN 1989 Conference on Programming language design and implementation, PLDI '89, page 246--257, New York, NY, USA, 1989. ACM. ISBN 0-89791-306-X. Google Scholar
Digital Library
- Chiyan Chen and Hongwei Xi. Meta-Programming through typeful code representation. Journal of Functional Programming, 15 (06): 797--835, 2005. Google Scholar
Digital Library
- R. Davies. A temporal-logic approach to binding-time analysis. In Proceedings of the 11th Annual IEEE Symposium on Logic in Computer Science, page 184. IEEE Computer Society, 1996. Google Scholar
Digital Library
- Rowan Davies and Frank Pfenning. A modal analysis of staged computation. In Proceedings of the 23rd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 258--270, St. Petersburg Beach, Florida, United States, 1996. ACM. Google Scholar
Digital Library
- Rowan Davies and Frank Pfenning. A modal analysis of staged computation. Journal of the ACM (JACM), 48: 555--604, may 2001. ACM ID: 382785. Google Scholar
Digital Library
- Edsko de Vries. Making Uniqueness Typing Less Unique. PhD thesis, Trinity College, Dublin, Ireland, 2008.Google Scholar
- Jason Eckhardt, Roumen Kaiabachev, Emir Pašalić, Kedar Swadi, and Walid Taha. Implicitly heterogeneous multi-stage programming. New Gen. Comput., 25 (3): 305--336, 2007. Google Scholar
Digital Library
- Matteo Frigo and Steven G. Johnson. The design and implementation of FFTW3. Proceedings of the IEEE, 93 (2): 216--231, 2005. Special issue on "Program Generation, Optimization, and Platform Adaptation".Google Scholar
Cross Ref
- Hideyuki Tanaka. peggy, feb 2012.Google Scholar
- Trevor Jim. What are principal typings and what are they good for? In Proceedings of the 23rd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 42--53, St. Petersburg Beach, Florida, United States, 1996. ACM. Google Scholar
Digital Library
- Yukiyoshi Kameyama, Oleg Kiselyov, and Chung-chieh Shan. Closing the stage: from staged code to typed closures. In Proceedings of the 2008 ACM SIGPLAN symposium on Partial evaluation and semantics-based program manipulation, pages 147--157, San Francisco, California, USA, 2008. ACM. Google Scholar
Digital Library
- Yukiyoshi Kameyama, Oleg Kiselyov, and Chung-Chieh Shan. Shifting the stage: staging with delimited control. Journal of Functional Programming, 21 (06): 617--662, 2011. Google Scholar
Digital Library
- Andrew J. Kennedy. Type inference and equational theories. Technical Report LIX/RR/96/09, LIX, Ecole Polytechnique, 91128 Palaiseau Cedex, France, sep 1996.Google Scholar
- Ik-Soon Kim, Kwangkeun Yi, and Cristiano Calcagno. A polymorphic modal type system for lisp-like multi-staged languages. In Conference record of the 33rd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 257--268, Charleston, South Carolina, USA, 2006. ACM. Google Scholar
Digital Library
- Oleg Kiselyov and Walid Taha. Relating FFTW and Split-Radix. In Embedded Software and Systems, pages 488--493. 2005. Google Scholar
Digital Library
- Geoffrey Mainland. Why it's nice to be quoted: Quasiquoting for haskell. In Haskell '07: Proceedings of the ACM SIGPLAN Workshop on Haskell, page 73--82, New York, NY, USA, 2007. ACM. Google Scholar
Digital Library
- Geoffrey Mainland. language-c-quote, 2010.Google Scholar
- Geoffrey Mainland and Greg Morrisett. Nikola: embedding compiled GPU functions in haskell. In Proceedings of the third ACM Haskell symposium on Haskell, pages 67--78, Baltimore, Maryland, USA, 2010. ACM. Google Scholar
Digital Library
- Geoffrey Mainland, Greg Morrisett, and Matt Welsh. Flask: Staged functional programming for sensor networks. In Proceeding of the 13th ACM SIGPLAN International Conference on Functional Programming (ICFP '08), page 335--346, New York, NY, USA, 2008. ACM. Google Scholar
Digital Library
- Urusula Martin and Tobias Nipkow. Boolean unification - The story so far. Journal of Symbolic Computation, 7 (3-4): 275--293, apr 1989. Google Scholar
Digital Library
- Aleksandar Nanevski. Meta-programming with names and necessity. In Proceedings of the seventh ACM SIGPLAN International Conference on Functional Programming, pages 206--217, Pittsburgh, PA, USA, 2002. ACM. Google Scholar
Digital Library
- Aleksandar Nanevski, Frank Pfenning, and Brigitte Pientka. Contextual modal type theory. ACM Transactions on Computational Logic (TOCL), 9: 23:1--23:49, jun 2008. ACM ID: 1352591. Google Scholar
Digital Library
- Markus Püschel, José M. F. Moura, Bryan Singer, Jianxin Xiong, Jeremy Johnson, David Padua, Manuela Veloso, and Robert W. Johnson. Spiral: A generator for Platform-Adapted libraries of signal processing alogorithms. International Journal of High Performance Computing Applications, 18 (1): 21--45, feb 2004. Google Scholar
Digital Library
- Didier Rémy. Type inference for records in natural extension of ML. Research Report 1431, Institut National de Recherche en Informatique et Automatisme, 1991.Google Scholar
- Didier Rémy. Syntactic theories and the algebra of record terms. Research Report 1869, Institut National de Recherche en Informatique et Automatisme, Rocquencourt, BP 105, 78 153 Le Chesnay Cedex, France, 1993.Google Scholar
- Morten Rhiger. First-class open and closed code fragments. In Proceedings of the Sixth Symposium on Trends in Functional Programming, 2005.Google Scholar
- Zhong Shao and Andrew W. Appel. Smartest recompilation. In Proceedings of the 20th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 439--450, Charleston, South Carolina, United States, 1993. ACM. Google Scholar
Digital Library
- Kedar Swadi, Walid Taha, Oleg Kiselyov, and Emir Pasalic. A monadic approach for avoiding code duplication when staging memoized functions. In Proceedings of the 2006 ACM SIGPLAN symposium on Partial evaluation and semantics-based program manipulation, PEPM '06, page 160--169, New York, NY, USA, 2006. ACM. ACM ID: 1111570. Google Scholar
Digital Library
- Walid Taha. A gentle introduction to multi-stage programming. In Christian Lengauer, Don S. Batory, Charles Consel, and Martin Odersky, editors, Domain-Specific Program Generation, volume 3016 of Lecture Notes in Computer Science, page 30--50. Springer, 2003.Google Scholar
- Walid Taha and Michael Florentin Nielsen. Environment classifiers. In Proceedings of the 30th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, POPL '03, page 26--37, New York, NY, USA, 2003. ACM. Google Scholar
Digital Library
- Walid Taha and Tim Sheard. Multi-stage programming with explicit annotations. In Proceedings of the 1997 ACM SIGPLAN symposium on Partial Evaluation and Semantics-Based Program Manipulation (PEPM '97), pages 203--217, Amsterdam, The Netherlands, 1997. ACM. Google Scholar
Digital Library
- Philip Wadler. Is there a use for linear logic? In Proceedings of the 1991 ACM SIGPLAN symposium on Partial evaluation and semantics-based program manipulation, PEPM '91, page 255--273, New York, NY, USA, 1991. ACM. ISBN 0-89791-433-3. Google Scholar
Digital Library
- Stephanie Weirich, Dimitrios Vytiniotis, Simon L. Peyton Jones, and Steve Zdancewic. Generative type abstraction and type-level computation. In Proceedings of the 38th ACM SIGPLAN-SIGACT symposium on Principles of programming languages (POPL '11), Austin, TX, 2011. Google Scholar
Digital Library
- R. Clint Whaley and Antoine Petitet. Minimizing development and maintenance costs in supporting persistently optimized BLAS. Softw. Pract. Exper., 35 (2): 101--121, 2005. Google Scholar
Digital Library
- Hongwei Xi, Chiyan Chen, and Gang Chen. Guarded recursive datatype constructors. In Proceedings of the 30th ACM SIGPLAN-SIGACT symposium on Principles of programming languages - POPL '03, pages 224--235, New Orleans, Louisiana, USA, 2003. Google Scholar
Digital Library
Index Terms
Explicitly heterogeneous metaprogramming with MetaHaskell
Recommendations
A Survey of Metaprogramming Languages
Metaprogramming is the process of writing computer programs that treat programs as data, enabling them to analyze or transform existing programs or generate new ones. While the concept of metaprogramming has existed for several decades, activities ...
Explicitly heterogeneous metaprogramming with MetaHaskell
ICFP '12: Proceedings of the 17th ACM SIGPLAN international conference on Functional programmingLanguages with support for metaprogramming, like MetaOCaml, offer a principled approach to code generation by guaranteeing that well-typed metaprograms produce well-typed programs. However, many problem domains where metaprogramming can fruitfully be ...
Type-Directed Elaboration of Quasiquotations: A High-Level Syntax for Low-Level Reflection
IFL '14: Proceedings of the 26nd 2014 International Symposium on Implementation and Application of Functional LanguagesIdris's reflection features allow Idris metaprograms to manipulate a representation of Idris's core language as a datatype, but these reflected terms were designed for ease of type checking and are therefore exceedingly verbose and tedious to work with. ...







Comments