Skip to main content

DSL Implementation in MetaOCaml, Template Haskell, and C++

  • Chapter

Part of the book series: Lecture Notes in Computer Science ((LNCS,volume 3016))

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.

This is a preview of subscription content, log in via an institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Bjesse, P., Claessen, K., Sheeran, M., Singh, S.: Lava: Hardware design in Haskell. ACM SIGPLAN Notices 34(1), 174–184 (1999)

    Article  Google Scholar 

  2. 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)

    Chapter  Google Scholar 

  3. Chandra, R., Dagum, L., Kohr, D.: Parallel Programming in OpenMP++. Morgan Kaufmann, San Francisco (2000)

    Google Scholar 

  4. Courtney, A.: Frappé: Functional reactive programming in Java. In: Proceedings of Symposium on Practical Aspects of Declarative Languages. ACM, New York (2001)

    Google Scholar 

  5. Czarnecki, K., Eisenecker, U.W.: Synthesizing objects. In: Guerraoui, R. (ed.) ECOOP 1999. LNCS, vol. 1628, pp. 18–42. Springer, Heidelberg (1999)

    Chapter  Google Scholar 

  6. Czarnecki, K., Eisenecker, U.W.: Generative Programming: Methods, Tools, and Applications. Addison-Wesley, Reading (2000)

    Google Scholar 

  7. Czarnecki, K., Eisenecker, U.W.: Named parameters for configuration generators (2000), http://www.generative-programming.org/namedparams/

  8. 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)

    Chapter  Google Scholar 

  9. Jones, S.P. (ed.): Haskell 98 language and libraries. Journal of Functional Programming 13(1), 1–255 (2003)

    Google Scholar 

  10. Elliott, C., Finne, S., de Moore, O.: Compiling embedded languages. In: [48], pp. 9–27 (2000)

    Google Scholar 

  11. Elliott, C., Hudak, P.: Functional reactive animation. In: International Conference on Functional Programming, June 1997, pp. 163–173 (1997)

    Google Scholar 

  12. Finne, S., Peyton Jones, S.L.: Pictures: A simple structured graphics model. In: Proceedings of Glasgow Functional Programming Workshop (July 1995)

    Google Scholar 

  13. Futamura, Y.: Partial evaluation of computation: An approach to a compiler-compiler. Systems, Computers, Controls 2(5), 45–50 (1971)

    Google Scholar 

  14. 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)

    Google Scholar 

  15. Gurtovoy, A.: Boost MPL Library (Template metaprogramming framework), http://www.boost.org/libs/mpl/doc/

  16. 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)

    Google Scholar 

  17. Haney, S., Crotinger, J., Karmesin, S., Smith, S.: Pete: The portable expression template engine. Dr. Dobbs Journal (October 1999)

    Google Scholar 

  18. Hudak, P., Makucevich, T., Gadde, S., Whong, B.: Haskore music notation – an algebra of music. Journal of Functional Programming 6(3), 465–483 (1996)

    Article  Google Scholar 

  19. Hudak, P.: Building domain specific embedded languages. ACM Computing Surveys 28A(electronic) (December 1996)

    Google Scholar 

  20. Hudak, P.: The Haskell School of Expression – Learning Functional Programming through Multimedia. Cambridge University Press, New York (2000)

    Google Scholar 

  21. 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)

    Google Scholar 

  22. Hutton, G.: Combinator parsing. Journal of Functional Programming (1993)

    Google Scholar 

  23. ISO/IEC. Programming languages – C++. ISO/IEC 14882 Standard (October 2003)

    Google Scholar 

  24. 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)

    Google Scholar 

  25. 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)

    Google Scholar 

  26. Jones, N.D., Gomard, C.K., Sestoft, P.: Partial Evaluation and Automatic Program Generation. Prentice-Hall, Englewood Cliffs (1993)

    MATH  Google Scholar 

  27. 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)

    Chapter  Google Scholar 

  28. Lynagh, I.: Template Haskell: A report from the field (May 2003), http://web.comlab.ox.ac.uk/oucl/work/ian.lynagh/papers/

  29. Lynagh, I.: Unrolling and simplifying expressions with Template Haskell (May 2003), http://web.comlab.ox.ac.uk/oucl/work/ian.lynagh/papers/

  30. Maddock, J., Cleary, S., et al.: Boost type traits library, http://www.boost.org/libs/typetraits/

  31. 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)

    Google Scholar 

  32. 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)

    Google Scholar 

  33. MetaOCaml: A compiled, type-safe multi-stage programming language (2003), Available online from: http://www.metaocaml.org/

  34. Moggi, E.: Notions of computation and monads. Information and Computation 93(1) (1991)

    Google Scholar 

  35. Myers, N.C.: Traits: a new and useful template technique. C++ Report 7(5) (June 1995)

    Google Scholar 

  36. 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)

    Chapter  Google Scholar 

  37. 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)

    Article  MATH  MathSciNet  Google Scholar 

  38. 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

  39. 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)

    Google Scholar 

  40. Peterson, J., Hager, G., Hudak, P.: A language for declarative robotic programming. In: Proceedings of IEEE Conf. on Robotics and Automation (1999)

    Google Scholar 

  41. 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)

    Chapter  Google Scholar 

  42. Rice Students. Multi-stage programming course projects (2000), http://www.cs.rice.edu/~taha/teaching/

  43. 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)

    Google Scholar 

  44. 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)

    Chapter  Google Scholar 

  45. 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)

    Chapter  Google Scholar 

  46. Striegnitz, J., Smith, S.: An expression template aware lambda function. In: First Workshop on C++ Template Programming, Erfurt, Germany (October 2000)

    Google Scholar 

  47. Taha, W.: Multi-Stage Programming: Its Theory and Applications. PhD thesis, Oregon Graduate Institute of Science and Technology (1999); Available from [38]

    Google Scholar 

  48. Taha, W. (ed.): SAIG 2000. LNCS, vol. 1924. Springer, Heidelberg (2000)

    MATH  Google Scholar 

  49. 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)

    Google Scholar 

  50. Taha, W., Johann, P.: Staged notational definitions. In: Pfenning, F., Smaragdakis, Y. (eds.) GPCE 2003. LNCS, vol. 2830, pp. 97–116. Springer, Heidelberg (2003)

    Chapter  Google Scholar 

  51. 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)

    Chapter  Google Scholar 

  52. Taha, W., Sheard, T.: MetaML: Multi-stage programming with explicit annotations. Theoretical Computer Science 248(1-2) (2000)

    Google Scholar 

  53. 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)

    Google Scholar 

  54. Unruh, E.: Prime number computation. Internal document, ANSI X3J16-94- 0075/ISO WG21-462 (1994)

    Google Scholar 

  55. Veldhuizen, T., Ponnambalam, K.: Linear algebra with C++ template metaprograms. Dr. Dobb’s Journal of Software Tools 21(8), 38–44 (1996)

    Google Scholar 

  56. Veldhuizen, T.L.: Expression templates. C++ Report 7(5), 26–31 (1995)

    Google Scholar 

  57. Veldhuizen, T.L.: Template metaprograms. C++ Report 7(4), 36–43 (1995)

    Google Scholar 

  58. Wile, D.: Popart: Producer of parsers and related tools. system builders’ manual. Technical report, USC Information Sciences Institute (1981)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints 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

Publish with us

Policies and ethics