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

Regular Paper
  • 101 Downloads

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.

Keywords

Defunctionalization Higher-order functions Type constructors Concepts Program transformation 

References

  1. 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. 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)Google Scholar
  3. 3.
    Bagge, A.H., Haveraaen, M.: Axiom-based transformations: optimisation and testing. Electron. Notes Theor. Comput. Sci. 238(5), 17–33 (2009)CrossRefGoogle Scholar
  4. 4.
    Botta, N., Ionescu, C.: Relation-based computations in a monadic BSP model. Parallel Comput. 33(12), 795–821 (2007)CrossRefGoogle Scholar
  5. 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)Google Scholar
  6. 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. 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)CrossRefMATHMathSciNetGoogle Scholar
  8. 8.
    Boost C++ Libraries. http://www.boost.org/. Accessed 2 Oct 2013
  9. 9.
    Broberg, N.: The haskell-src-exts package. http://hackage.haskell.org/package/haskell-src-exts. Accessed 28 Nov 2011
  10. 10.
    de Guzman, J., Marsden, D.: Fusion library homepage. http://www.boost.org/libs/fusion. Accessed 28 Nov 2011
  11. 11.
    The GNU Compiler Collection (GCC). http://gcc.gnu.org/. Accessed 2 Oct 2013
  12. 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)CrossRefMATHGoogle Scholar
  13. 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)Google Scholar
  14. 14.
    Gregor, D.: ConceptGCC. http://www.generic-programming.org/software/ConceptGCC/. Accessed 2 Oct 2013
  15. 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. 16.
    Gregor, D., Stroustrup, B.: Concepts (Revision 1). Technical report. Document number: N2081=06-0151, Project: Programming Language C++. Evolution Working Group (2006)Google Scholar
  17. 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)Google Scholar
  18. 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)Google Scholar
  19. 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)Google Scholar
  20. 20.
    Ionescu, C.: Vulnerability modelling and monadic dynamical systems. PhD thesis, Freie Universität Berlin (2008)Google Scholar
  21. 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. 22.
    Jones, S.P.: Haskell 98 Language and Libraries: The Revised Report. Cambridge University Press, Cambridge (2003)Google Scholar
  23. 23.
    Järvi, J., Powell, G., Lumsdaine, A.: The lambda library unnamed functions in C++. Softw. Pract. Exp. 33, 259–291 (2003)CrossRefMATHGoogle Scholar
  24. 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)Google Scholar
  25. 25.
    Lincke, D.: A transformational approach to generic programming. http://www.pik-potsdam.de/members/lincke/tagp. Accessed 26 June 2012
  26. 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)Google Scholar
  27. 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) Google Scholar
  28. 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)Google Scholar
  29. 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)Google Scholar
  30. 30.
    McNamara B.: Multiparadigm programming: novel devices for implementing functional and logic programming constructs in C++. PhD thesis, Georgia Institute of Technology (2004)Google Scholar
  31. 31.
    Stepanov, A.A., Lee, M.: The Standard Template Library. Technical report X3J16/94-0095, WG21/N0482 (1994)Google Scholar
  32. 32.
    Sommerville, I.: Software Engineering. Addison-Wesley, Amsterdam (2006)Google Scholar
  33. 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)Google Scholar
  34. 34.
    Vandervoorde, D., Josuttis, N.M.: C++ Templates: The Complete Guide. Addison-Wesley, Amsterdam (2002)Google Scholar
  35. 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)CrossRefGoogle Scholar
  36. 36.
    Zalewski, M.: Generic Programming with Concepts. PhD thesis, Chalmers University of Technology, Gothenburg (2008)Google Scholar
  37. 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)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2014

Authors and Affiliations

  1. 1.Global Climate ForumBerlinGermany
  2. 2.Institute for Software SystemsHamburg University of TechnologyHamburgGermany
  3. 3.Research Domain Transdisciplinary Concepts and MethodsPotsdam Institute for Climate Impact Research (PIK)PotsdamGermany

Personalised recommendations