MetaHaskell
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.
MetaHaskell Publications
Explicitly Heterogeneous Metaprogramming with
MetaHaskell. . Proceedings of the Seventeenth ACM
SIGPLAN International Conference on Functional Programming (ICFP '12),
Copenhagen, Denmark,
September 2012.
[doi]
[pdf]
[bib]
@inproceedings{mainland12metahaskell,
address = {Copenhagen, Denmark},
title = {Explicitly heterogeneous metaprogramming with {M}eta{H}askell},
isbn = {978-1-4503-1054-3},
url = {http://doi.acm.org/10.1145/2364527.2364572},
doi = {10.1145/2364527.2364572},
booktitle = {Proceedings of the 17th {ACM} {SIGPLAN} International Conference on Functional Programming {(ICFP} '12)},
author = {Mainland, Geoffrey},
year = {2012},
keywords = {linear languages, metaprogramming, open terms, quasiquotation, type systems},
pages = {311--322},
}
MetaHaskell Implementation
The mhc 0.1 release is available here. You will need GHC 7.0.