Skip to main content
Log in

Functional prototypes for generic C++ libraries: a transformational approach based on higher-order, typed signatures

  • Regular Paper
  • Published:
International Journal on Software Tools for Technology Transfer Aims and scope Submit manuscript

Abstract

This paper presents a method for developing generic C++ software libraries from functional prototypes, based on program transformation. More precisely, the type signatures of generic functions, i.e., functions parameterized on types, are transformed. This transformation maps type-level expressions from functional higher-order, typed languages to type-level expressions in C++. In particular, type-level functional constructs such as higher-order functions and type constructors, are mapped to type parameters of generics that are constrained with appropriate concepts. The core of the transformation is a novel form of “defunctionalization” at the level of types. To make the transformation retargetable, we based it on two kernel languages that can be bound to different functional and object-oriented languages. For this paper, we use bindings to Haskell as front end and C++ with concepts as back end. Our transformational approach presents an alternative to a language extension and is useful particularly for functional prototyping where functional features are employed at specification time. We illustrate our approach by a case study: we show how we developed a generic C++ library for vulnerability modeling in the context of global change from a functional prototype in Haskell.

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

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7
Fig. 8
Fig. 9

Similar content being viewed by others

References

  1. Abrahams, D., Gurtovoy, A.: C++ Template Metaprogramming. Concepts, Tools, and Techniques from Boost and Beyond. C++ In-Depth Series. Addison-Wesley, Amsterdam (2005)

    Google Scholar 

  2. Brooks, N., Adger, W.N.: Country level risk measures of climate-related natural disasters an implications for adaptation to climate change. In: Tyndall Center Working Paper, vol. 26 (2003)

  3. Bagge, A.H., Haveraaen, M.: Axiom-based transformations: optimisation and testing. Electron. Notes Theor. Comput. Sci. 238(5), 17–33 (2009)

    Article  Google Scholar 

  4. Botta, N., Ionescu, C.: Relation-based computations in a monadic BSP model. Parallel Comput. 33(12), 795–821 (2007)

    Article  Google Scholar 

  5. Botta, N., Ionescu, C., Linstead, C., Klein, R.: Structuring Distributed Relation-Based Computations with SCDRC. PIK Report 103, Potsdam Institute for Climate Impact Research, Potsdam (2006)

  6. Bernardy, J., Jansson, P., Zalewski, M., Schupp, S., Priesnitz, A.: Generic programming with C++ concepts and Haskell type classes: a comparison. J. Funct. Program. 20(3—4), 271–302 (2010)

    Google Scholar 

  7. Botta, N., Mandel, A., Ionescu, C., Hofmann, M., Lincke, D., Schupp, S., Jaeger, C.: A functional framework for agent-based models of exchange. Appl. Math. Comput. 218(8), 4025–4040 (2011)

    Article  MATH  MathSciNet  Google Scholar 

  8. Boost C++ Libraries. http://www.boost.org/. Accessed 2 Oct 2013

  9. Broberg, N.: The haskell-src-exts package. http://hackage.haskell.org/package/haskell-src-exts. Accessed 28 Nov 2011

  10. de Guzman, J., Marsden, D.: Fusion library homepage. http://www.boost.org/libs/fusion. Accessed 28 Nov 2011

  11. The GNU Compiler Collection (GCC). http://gcc.gnu.org/. Accessed 2 Oct 2013

  12. Garcia, R., Järvi, J., Lumsdaine, A., Siek, J., Willcock, J.: An extended comparative study of language support for generic programming. J. Funct. Program. 17, 145–205 (2007)

    Article  MATH  Google Scholar 

  13. Gregor, D., Järvi, J., Siek, J., Stroustrup, B., Dos Reis, G., Lumsdaine, A.: Concepts: linguistic support for generic programming in C++. In: Proceedings of the 21st Annual ACM SIGPLAN Conference on Object-oriented Programming Systems, Languages, and Applications, pp. 291–310. ACM, New York (2006)

  14. Gregor, D.: ConceptGCC. http://www.generic-programming.org/software/ConceptGCC/. Accessed 2 Oct 2013

  15. Gregor, D.: What happened in Frankfurt? C++-next, the next generation of C++. http://cpp-next.com/archive/2009/08/what-happened-in-frankfurt/ (2009). Accessed 2 Oct 2013

  16. Gregor, D., Stroustrup, B.: Concepts (Revision 1). Technical report. Document number: N2081=06-0151, Project: Programming Language C++. Evolution Working Group (2006)

  17. 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++ (2008)

  18. Hudak, P., Jones, M.P.: Haskell vs. Ada vs. C++ vs. Awk vs. \(\ldots \) An Experiment in Software Prototyping Productivity. Research report YALEU/DCS/RR-1049, Department of Computer Science, Yale University, New Haven (1994)

  19. Haeri, S.H., Schupp, S.: Functional metaprogramming in C++ and cross-lingual development with Haskell. In: Proceedings of the 23rd Symposium on Implementation and Application of Functional Languages, IFL2011 (2011)

  20. Ionescu, C.: Vulnerability modelling and monadic dynamical systems. PhD thesis, Freie Universität Berlin (2008)

  21. Janssen, M.A., Ostrom, E.: Resilience, vulnerability and adaptation: a cross-cutting theme of the international human dimensions programme on global environmental change. Glob. Environ. Chang. 16(3), 237–239 (2006) (Editorial)

    Google Scholar 

  22. Jones, S.P.: Haskell 98 Language and Libraries: The Revised Report. Cambridge University Press, Cambridge (2003)

    Google Scholar 

  23. Järvi, J., Powell, G., Lumsdaine, A.: The lambda library unnamed functions in C++. Softw. Pract. Exp. 33, 259–291 (2003)

    Article  MATH  Google Scholar 

  24. Lincke, D., Ionescu, C., Botta, N.: A generic library for earth system modelling based on monadic systems. In: Ehlers, M., Ehlers, M., Behncke, K., Gerstengarbe, F.- W., Hillen, F., Koppers, L., Stroinck, L., Wächter, J. (eds.) Proceedings of the Digital earth summit on geoinformatics 2008: tools for global change research, pp. 188–194. Wichmann, Heidelberg (2008)

  25. Lincke, D.: A transformational approach to generic programming. http://www.pik-potsdam.de/members/lincke/tagp. Accessed 26 June 2012

  26. Lincke, D.: A transformational approach to generic software development based on higher-order, typed (HOT) functional signatures. PhD thesis, Technical University Hamburg-Harburg (2012)

  27. Lincke, D., Jansson, P., Zalewski, M., Ionescu, C.: Generic libraries in C++ with concepts from high-level domain descriptions in Haskell. A domain-specific library for computational vulnerability assessment. In: Proceedings of the IFIP Working Conference on Domain Specific Languages, pp. 236–261 (2009)

  28. Lämmel, R., Peyton Jones, S.: Scrap your boilerplate: a practical design pattern for generic programming. In: Proceedings of the 2003 ACM SIGPLAN International Workshop on Types in Languages Design and Implementation, (TLDI ’03), SIGPLAN Not. 38(3), 26–37 (2003)

  29. Lincke, D., Schupp, S.: From hot to cool: transforming higher-order typed languages to concept-constrained object-oriented languages. In: Proceedings of the 12th Workshop on Language Descriptions, Tools and Applications (LDTA 2012), Tallinn (2012)

  30. McNamara B.: Multiparadigm programming: novel devices for implementing functional and logic programming constructs in C++. PhD thesis, Georgia Institute of Technology (2004)

  31. Stepanov, A.A., Lee, M.: The Standard Template Library. Technical report X3J16/94-0095, WG21/N0482 (1994)

  32. Sommerville, I.: Software Engineering. Addison-Wesley, Amsterdam (2006)

    Google Scholar 

  33. Turner, D.A.: Functional programs as executable specifications. In: Proceedings of a Discussion Meeting of the Royal Society of London on Mathematical Logic and Programming Languages, pp. 29–54. Prentice-Hall Inc, USA (1985)

  34. Vandervoorde, D., Josuttis, N.M.: C++ Templates: The Complete Guide. Addison-Wesley, Amsterdam (2002)

    Google Scholar 

  35. Wolf, S., Hinkel, J., Hallier, M., Bisaro, A., Lincke, D., Ionescu, C., Klein, R.J.T.: Clarifying vulnerability definitions and assessments using formalisation. Int. J. Clim. Chang. Strateg. Manag. 5, 54–70 (2013)

    Article  Google Scholar 

  36. Zalewski, M.: Generic Programming with Concepts. PhD thesis, Chalmers University of Technology, Gothenburg (2008)

  37. Zalewski, M., Priesnitz, A., Ionescu, C., Botta, N., Schupp, S.: Multi-language library development. From Haskell type classes to C++ concepts. In: Striegnitz, J. (ed.) Proceedings of 6th International Workshop on Multiparadigm Programming with Object-Oriented Languages (2007)

Download references

Acknowledgments

We thank Carlo Jaeger, Nicola Botta, and Patrik Jansson for insightful comments and interesting discussions. We also thank the editor and two anonymous reviewers for their constructive comments, which helped us to improve the manuscript. The research in this paper was partly supported by a grant from the European Union research project ADAM under Contract Number GOCE-018476 and by Grant 0702717 from the National Science Foundation.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Daniel Lincke.

Rights and permissions

Reprints and permissions

About this article

Cite this article

Lincke, D., Schupp, S. & Ionescu, C. Functional prototypes for generic C++ libraries: a transformational approach based on higher-order, typed signatures. Int J Softw Tools Technol Transfer 17, 91–105 (2015). https://doi.org/10.1007/s10009-014-0299-0

Download citation

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10009-014-0299-0

Keywords

Navigation