Generic Libraries in C++ with Concepts from High-Level Domain Descriptions in Haskell

A Domain-Specific Library for Computational Vulnerability Assessment
  • Daniel Lincke
  • Patrik Jansson
  • Marcin Zalewski
  • Cezar Ionescu
Part of the Lecture Notes in Computer Science book series (LNCS, volume 5658)


A class of closely related problems, a problem domain, can often be described by a domain-specific language, which consists of algorithms and combinators useful for solving that particular class of problems. Such a language can be of two kinds: it can form a new language or it can be embedded as a sublanguage in an existing one. We describe an embedded DSL in the form of a library which extends a general purpose language. Our domain is that of vulnerability assessment in the context of climate change, formally described at the Potsdam Institute for Climate Impact Research. The domain is described using Haskell, yielding a domain specific sublanguage of Haskell that can be used for prototyping of implementations.

In this paper we present a generic C++ library that implements a domain-specific language for vulnerability assessment, based on the formal Haskell description. The library rests upon and implements only a few notions, most importantly, that of a monadic system, a crucial part in the vulnerability assessment formalisation. We describe the Haskell description of monadic systems and we show our mapping of the description to generic C++ components. Our library heavily relies on concepts, a C++ feature supporting generic programming: a conceptual framework forms the domain-specific type system of our library. By using functions, parametrised types and concepts from our conceptual framework, we represent the combinators and algorithms of the domain. Furthermore, we discuss what makes our library a domain specific language and how our domain-specific library scheme can be used for other domains (concerning language design, software design, and implementation techniques).


Vulnerability Assessment Generic Library Type Constructor Translation Scheme Template Parameter 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


  1. C++ Standard, ISO/IEC 14882:2003(E). ANSI-ISO-IEC, ANSI standards for information technology edition (2003)Google Scholar
  2. Austern, M.H.: Generic Programming and the STL: Using and Extending the C++ Standard Template Library. Addison-Wesley, Reading (1998)Google Scholar
  3. Bernardy, J.-P., Jansson, P., Zalewski, M., Schupp, S., Priesnitz, A.: A comparison of C++ concepts and Haskell type classes. In: Proc. ACM SIGPLAN Workshop on Generic Programming, pp. 37–48. ACM, New York (2008)CrossRefGoogle Scholar
  4. Brooks, N.: Vulnerability, risk and adaptation: A conceptual framework. Tyndall Center Working Paper 38 (2003)Google Scholar
  5. Chakravarty, M.M.T., Keller, G., Jones, S.P.: Associated type synonyms. In: ICFP 2005: Proceedings of the tenth ACM SIGPLAN international conference on Functional programming, pp. 241–253. ACM, New York (2005)CrossRefGoogle Scholar
  6. Claessen, K., Hughes, J.: QuickCheck: A lightweight tool for random testing of Haskell programs. In: ICFP 2000: International Conference on Functional Programming, pp. 268–279. ACM, New York (2000)Google Scholar
  7. Garcia, R., Jarvi, J., Lumsdaine, A., Siek, J., Willcock, J.: An extended comparative study of language support for generic programming. J. Funct. Program 17(2), 145–205 (2007)CrossRefzbMATHGoogle Scholar
  8. Gregor, D., Järvi, J., Siek, J., Stroustrup, B., Dos Reis, G., Lumsdaine, A.: Concepts: Linguistic support for generic programming in C++. In: Proc. ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), pp. 291–310. ACM Press, New York (2006)Google Scholar
  9. Gregor, D., Marcus, M., Witt, T., Lumsdaine, A.: Foundational concepts for the C++ox standard library (revision 4). Technical Report N2737=08-0247, ISO/IEC JTC 1, Information Technology, Subcommittee SC 22, Programming Language C++ (August 2008a)Google Scholar
  10. Gregor, D., Siek, J., Lumsdaine, A.: Iterator concepts for the C++ox standard library (revision 4). Technical Report N2739=08-0249, ISO/IEC JTC 1, Information Technology, Subcommittee SC 22, Programming Language C++ (August 2008b)Google Scholar
  11. Gregor, D., Stroustrup, B., Widman, J., Siek, J.: Proposed wording for concepts (revision 8). Technical Report N2741=08-0251, ISO/IEC JTC1/SC22/WG21 - C++ (August 2008c)Google Scholar
  12. de Guzman, J., Marsden, D.: Fusion library homepage (March 2009),
  13. Halpern, P.: Defects and proposed resolutions for allocator concepts. Technical Report N2810=08-0320, ISO/IEC JTC1/SC22/WG21 - C++ (December 2008)Google Scholar
  14. Hudak, P.: Building domain-specific embedded languages. ACM Comput. Surv., 196 (1996)Google Scholar
  15. Ionescu, C.: Vulnerability Modelling and Monadic Dynamical Systems. PhD thesis, Freie Universität Berlin (2009)Google Scholar
  16. Janssen, M.A., Ostrom, E.: Resilience, vulnerability and adaptation: A cross-cutting theme of the international human dimensions programme on global environmental change. Global Environmental Change 16(3), 237–239 (2006) (Editorial)CrossRefGoogle Scholar
  17. Jansson, P., Jeuring, J.: Polytypic data conversion programs. Science of Computer Programming 43(1), 35–75 (2002)MathSciNetCrossRefzbMATHGoogle Scholar
  18. Järvi, J., Powell, G., Lumsdaine, A.: The lambda library: Unnamed functions in C++. Software: Practice and Experience 33(3), 259–291 (2003)zbMATHGoogle Scholar
  19. Kamin, S.N., Hyatt, D.: A special-purpose language for picture-drawing. In: Proc. Conference on Domain-Specific Languages (DSL), pp. 297–310. USENIX Association (1997)Google Scholar
  20. McNamara, B., Smaragdakis, Y.: Functional programming with the FC++ library. J. of Functional Programming 14(4), 429–472 (2004)CrossRefzbMATHGoogle Scholar
  21. Oliveira, B.C.d.S., Hinze, R., Löh, A.: Extensible and modular generics for the masses. In: Nilsson, H. (ed.) Trends in Functional Programming, pp. 199–216 (2006)Google Scholar
  22. Peterson, J., Hudak, P., Elliott, C.: Lambda in motion: Controlling robots with haskell. In: Gupta, G. (ed.) PADL 1999. LNCS, vol. 1551, pp. 91–105. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  23. Petoukhov, V., Ganopolski, A., Brovkin, V., Claussen, M., Eliseev, A., Kubatzki, C., Rahmstorf, S.: CLIMBER-2: a climate system model of intermediate complexity. Part I: model description and performance for present climate. Climate dynamics 16, 1–17 (2000)CrossRefGoogle Scholar
  24. Peyton Jones, S. (ed.): Haskell 98 Language and Libraries: The Revised Report. Cambridge University Press, Cambridge (2003)zbMATHGoogle Scholar
  25. Schrijvers, T., Peyton Jones, S., Chakravarty, M., Sulzmann, M.: Type checking with open type functions. In: ICFP 2008: Proceeding of the 13th ACM SIGPLAN international conference on Functional programming, pp. 51–62. ACM, New York (2008)Google Scholar
  26. Siek, J.G., Lee, L.Q., Lumsdaine, A.: The Boost Graph Library: User Guide and Reference Manual. Addison-Wesley, Reading (2002)Google Scholar
  27. Stepanov, A.A., Lee, M.: The Standard Template Library. Technical Report HPL-94-34, Hewlett-Packard Laboratories, Revised in, as tech. rep. HPL-95-11 (May 1994)Google Scholar
  28. Stroustrup, B.: The C++ Programming Language, 3rd edn. Addison-Wesley, Reading (1997)zbMATHGoogle Scholar
  29. Vandervoorde, D., Josuttis, N.M.: C++ Templates: The Complete Guide. Addison-Wesley, Amsterdam (2002)Google Scholar
  30. Wadler, P., Blott, S.: How to make ad-hoc polymorphism less ad hoc. In: Proc. 16th ACM SIGPLAN-SIGACT Symp. on Principles of Programming Languages (POPL), pp. 60–76. ACM Press, New York (1989)CrossRefGoogle Scholar
  31. Wolf, S., Lincke, D., Hinkel, J., Ionescu, C., Bisaro, S.: A formal framework of vulnerability. Final deliverable to the ADAM project. FAVAIA working paper 8, Potsdam Institute for Climate Impact Research, Potsdam, Germany (2008),
  32. Zalewski, M., Priesnitz, A.P., Ionescu, C., Botta, N., Schupp, S.: Multi-language library development: From Haskell type classes to C++ concepts. In: Striegnitz, J. (ed.) Proc. 6th Int. Workshop on Multiparadigm Programming With Object-Oriented Languages (MPOOL) (July 2007)Google Scholar

Copyright information

© IFIP International Federation for Information Processing 2009

Authors and Affiliations

  • Daniel Lincke
    • 1
  • Patrik Jansson
    • 2
  • Marcin Zalewski
    • 2
  • Cezar Ionescu
    • 1
  1. 1.Potsdam Institute for Climate Impact ResearchPotsdamGermany
  2. 2.Chalmers University of Technology & University of GothenburgGothenburgSweden

Personalised recommendations