Abstract
A wide range of domain-specific languages (DSLs) has been implemented successfully by embedding them in general purpose languages. This paper reviews embedding, and summarizes how two alternative techniques – staged interpreters and templates – can be used to overcome the limitations of embedding. Both techniques involve a form of generative programming. The paper reviews and compares three programming languages that have special support for generative programming. Two of these languages (MetaOCaml and Template Haskell) are research languages, while the third (C++) is already in wide industrial use. The paper identifies several dimensions that can serve as a basis for comparing generative languages.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Bjesse, P., Claessen, K., Sheeran, M., Singh, S.: Lava: Hardware design in Haskell. ACM SIGPLAN Notices 34(1), 174–184 (1999)
Calcagno, C., Taha, W., Huang, L., Leroy, X.: Implementing multi-stage languages using asts, gensym, and reflection. In: Pfenning, F., Smaragdakis, Y. (eds.) GPCE 2003. LNCS, vol. 2830, pp. 57–76. Springer, Heidelberg (2003)
Chandra, R., Dagum, L., Kohr, D.: Parallel Programming in OpenMP++. Morgan Kaufmann, San Francisco (2000)
Courtney, A.: Frappé: Functional reactive programming in Java. In: Proceedings of Symposium on Practical Aspects of Declarative Languages. ACM, New York (2001)
Czarnecki, K., Eisenecker, U.W.: Synthesizing objects. In: Guerraoui, R. (ed.) ECOOP 1999. LNCS, vol. 1628, pp. 18–42. Springer, Heidelberg (1999)
Czarnecki, K., Eisenecker, U.W.: Generative Programming: Methods, Tools, and Applications. Addison-Wesley, Reading (2000)
Czarnecki, K., Eisenecker, U.W.: Named parameters for configuration generators (2000), http://www.generative-programming.org/namedparams/
Czarnecki, K., Eisenecker, U.W., Glück, R., Vandevoorde, D., Veldhuizen, T.: Generative programming and active libraries (extended abstract). In: Jazayeri, M., Musser, D.R., Loos, R.G.K. (eds.) Dagstuhl Seminar 1998. LNCS, vol. 1766, pp. 25–39. Springer, Heidelberg (2000)
Jones, S.P. (ed.): Haskell 98 language and libraries. Journal of Functional Programming 13(1), 1–255 (2003)
Elliott, C., Finne, S., de Moore, O.: Compiling embedded languages. In: [48], pp. 9–27 (2000)
Elliott, C., Hudak, P.: Functional reactive animation. In: International Conference on Functional Programming, June 1997, pp. 163–173 (1997)
Finne, S., Peyton Jones, S.L.: Pictures: A simple structured graphics model. In: Proceedings of Glasgow Functional Programming Workshop (July 1995)
Futamura, Y.: Partial evaluation of computation: An approach to a compiler-compiler. Systems, Computers, Controls 2(5), 45–50 (1971)
Ganz, S., Sabry, A., Taha, W.: Macros as multi-stage computations: Type-safe, generative, binding macros in MacroML. In: The International Conference on Functional Programming (ICFP 2001), Florence, Italy, September 2001. ACM, New York (2001)
Gurtovoy, A.: Boost MPL Library (Template metaprogramming framework), http://www.boost.org/libs/mpl/doc/
Hammond, K., Loogen, R., Berhold, J.: Automatic Skeletons in Template Haskell. In: Proceedings of 2003 Workshop on High Level Parallel Programming, Paris, France (June 2003)
Haney, S., Crotinger, J., Karmesin, S., Smith, S.: Pete: The portable expression template engine. Dr. Dobbs Journal (October 1999)
Hudak, P., Makucevich, T., Gadde, S., Whong, B.: Haskore music notation – an algebra of music. Journal of Functional Programming 6(3), 465–483 (1996)
Hudak, P.: Building domain specific embedded languages. ACM Computing Surveys 28A(electronic) (December 1996)
Hudak, P.: The Haskell School of Expression – Learning Functional Programming through Multimedia. Cambridge University Press, New York (2000)
Hughes, J.: Pretty-printing: an exercise in functional programming. In: Bird, R.S., Morgan, C.C., Woodcock, J.C.P. (eds.) Mathematics of Program Construction; Second International Conference; Proceedings, Berlin, Germany, pp. 11–13. Springer, Heidelberg (1993)
Hutton, G.: Combinator parsing. Journal of Functional Programming (1993)
ISO/IEC. Programming languages – C++. ISO/IEC 14882 Standard (October 2003)
Järvi, J., Powell, G.: The lambda library: Lambda abstraction in C++. In: Second Workshop on C++ Template Programming, Tampa Bay, Florida, USA (October 2001)
Jones, N.D.: What not to do when writing an interpreter for specialisation. In: Danvy, O., Thiemann, P., Glück, R. (eds.) Dagstuhl Seminar 1996. LNCS, vol. 1110, pp. 216–237. Springer, Heidelberg (1996)
Jones, N.D., Gomard, C.K., Sestoft, P.: Partial Evaluation and Automatic Program Generation. Prentice-Hall, Englewood Cliffs (1993)
Krishnamurthi, S., Felleisen, M., Friedman, D.P.: Synthesizing object-oriented and functional design to promote re-use. In: Jul, E. (ed.) ECOOP 1998. LNCS, vol. 1445, pp. 91–113. Springer, Heidelberg (1998)
Lynagh, I.: Template Haskell: A report from the field (May 2003), http://web.comlab.ox.ac.uk/oucl/work/ian.lynagh/papers/
Lynagh, I.: Unrolling and simplifying expressions with Template Haskell (May 2003), http://web.comlab.ox.ac.uk/oucl/work/ian.lynagh/papers/
Maddock, J., Cleary, S., et al.: Boost type traits library, http://www.boost.org/libs/typetraits/
Matthews, J., Cook, B., Launchbury, J.: Microprocessor specification in Hawk. In: Proceedings of the 1998 International Conference on Computer Languages, pp. 90–101. IEEE Computer Society Press, Los Alamitos (1998)
Mauny, M.: Parsers and printers as stream destructors embedded in functional languages. In: Proceedings of the Conference on Functional Programming Languages and Computer Architecture, pp. 360–370. ACM/IFIP (1989)
MetaOCaml: A compiled, type-safe multi-stage programming language (2003), Available online from: http://www.metaocaml.org/
Moggi, E.: Notions of computation and monads. Information and Computation 93(1) (1991)
Myers, N.C.: Traits: a new and useful template technique. C++ Report 7(5) (June 1995)
O’Donnell, J.: Overview of Hydra: A concurrent language for synchronous digital circuit design. In: Proceedings 16th International Parallel & Distributed Processing Symposium, April 2002, p. 234. IEEE Computer Society, Los Alamitos (2002); Workshop on Parallel and Distribued Scientific and Engineering Computing with Applications – PDSECA (abstract)
Okasaki, C.: Even higher-order functions for parsing or why would anyone ever want to use a sixth-order function? Journal of Functional Programming 8(2), 195–199 (1998)
Oregon Graduate Institute Technical Reports. P.O. Box 91000, Portland, OR 97291-1000,USA. Available online from: ftp://cse.ogi.edu/pub/tech-reports/README.html
Pašalić, E., Taha, W., Sheard, T.: Tagless staged interpreters for typed languages. In: The International Conference on Functional Programming (ICFP 2002), Pittsburgh, USA, October 2002. ACM, New York (2002)
Peterson, J., Hager, G., Hudak, P.: A language for declarative robotic programming. In: Proceedings of IEEE Conf. on Robotics and Automation (1999)
Jones, S.P., Wadler, P.: Imperative functional programming. In: The Symposium on Principles of Programming Languages (POPL 1993), January 1993, pp. 71–84. ACM, New York (1993)
Rice Students. Multi-stage programming course projects (2000), http://www.cs.rice.edu/~taha/teaching/
Sheard, T., El-Abidine Benaissa, Z., Pašalić, E.: DSL implementation using staging and monads. In: Second Conference on Domain-Specific Languages (DSL 1999), Austin, Texas, USENIX (1999)
Sheard, T., Jones, S.P.: Template metaprogramming for Haskell. In: Chakravarty, M.M.T. (ed.) ACM SIGPLAN Haskell Workshop 2002, October 2002, pp. 1–16. ACM Press, New York (2002)
Smaragdakis, Y., Batory, D.: Implementing layered designs with mixin layers. In: Jul, E. (ed.) ECOOP 1998. LNCS, vol. 1445, pp. 550–570. Springer, Heidelberg (1998)
Striegnitz, J., Smith, S.: An expression template aware lambda function. In: First Workshop on C++ Template Programming, Erfurt, Germany (October 2000)
Taha, W.: Multi-Stage Programming: Its Theory and Applications. PhD thesis, Oregon Graduate Institute of Science and Technology (1999); Available from [38]
Taha, W. (ed.): SAIG 2000. LNCS, vol. 1924. Springer, Heidelberg (2000)
Taha, W.: A sound reduction semantics for untyped CBN multi-stage computation. Or, the theory of MetaML is non-trivial. In: Proceedings of the Workshop on Partial Evaluation and Semantics-Based Program Maniplation (PEPM), Boston. ACM Press, New York (2000)
Taha, W., Johann, P.: Staged notational definitions. In: Pfenning, F., Smaragdakis, Y. (eds.) GPCE 2003. LNCS, vol. 2830, pp. 97–116. Springer, Heidelberg (2003)
Taha, W., Sheard, T.: Multi-stage programming with explicit annotations. In: Proceedings of the Symposium on Partial Evaluation and Semantic-Based Program Manipulation (PEPM), Amsterdam, pp. 203–217. ACM Press, New York (1997)
Taha, W., Sheard, T.: MetaML: Multi-stage programming with explicit annotations. Theoretical Computer Science 248(1-2) (2000)
Thiemann, P.: Programmable Type Systems for Domain Specific Languages. In: Comini, M., Falaschi, M. (eds.). Electronic Notes in Theoretical Computer Science, vol. 76. Elsevier, Amsterdam (2002)
Unruh, E.: Prime number computation. Internal document, ANSI X3J16-94- 0075/ISO WG21-462 (1994)
Veldhuizen, T., Ponnambalam, K.: Linear algebra with C++ template metaprograms. Dr. Dobb’s Journal of Software Tools 21(8), 38–44 (1996)
Veldhuizen, T.L.: Expression templates. C++ Report 7(5), 26–31 (1995)
Veldhuizen, T.L.: Template metaprograms. C++ Report 7(4), 36–43 (1995)
Wile, D.: Popart: Producer of parsers and related tools. system builders’ manual. Technical report, USC Information Sciences Institute (1981)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2004 Springer-Verlag Berlin Heidelberg
About this chapter
Cite this chapter
Czarnecki, K., O’Donnell, J.T., Striegnitz, J., Taha, W. (2004). DSL Implementation in MetaOCaml, Template Haskell, and C++. In: Lengauer, C., Batory, D., Consel, C., Odersky, M. (eds) Domain-Specific Program Generation. Lecture Notes in Computer Science, vol 3016. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-25935-0_4
Download citation
DOI: https://doi.org/10.1007/978-3-540-25935-0_4
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-22119-7
Online ISBN: 978-3-540-25935-0
eBook Packages: Springer Book Archive