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.
Similar content being viewed by others
References
Abrahams, D., Gurtovoy, A.: C++ Template Metaprogramming. Concepts, Tools, and Techniques from Boost and Beyond. C++ In-Depth Series. Addison-Wesley, Amsterdam (2005)
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)
Bagge, A.H., Haveraaen, M.: Axiom-based transformations: optimisation and testing. Electron. Notes Theor. Comput. Sci. 238(5), 17–33 (2009)
Botta, N., Ionescu, C.: Relation-based computations in a monadic BSP model. Parallel Comput. 33(12), 795–821 (2007)
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)
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)
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)
Boost C++ Libraries. http://www.boost.org/. Accessed 2 Oct 2013
Broberg, N.: The haskell-src-exts package. http://hackage.haskell.org/package/haskell-src-exts. Accessed 28 Nov 2011
de Guzman, J., Marsden, D.: Fusion library homepage. http://www.boost.org/libs/fusion. Accessed 28 Nov 2011
The GNU Compiler Collection (GCC). http://gcc.gnu.org/. Accessed 2 Oct 2013
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)
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)
Gregor, D.: ConceptGCC. http://www.generic-programming.org/software/ConceptGCC/. Accessed 2 Oct 2013
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
Gregor, D., Stroustrup, B.: Concepts (Revision 1). Technical report. Document number: N2081=06-0151, Project: Programming Language C++. Evolution Working Group (2006)
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)
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)
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)
Ionescu, C.: Vulnerability modelling and monadic dynamical systems. PhD thesis, Freie Universität Berlin (2008)
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)
Jones, S.P.: Haskell 98 Language and Libraries: The Revised Report. Cambridge University Press, Cambridge (2003)
Järvi, J., Powell, G., Lumsdaine, A.: The lambda library unnamed functions in C++. Softw. Pract. Exp. 33, 259–291 (2003)
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)
Lincke, D.: A transformational approach to generic programming. http://www.pik-potsdam.de/members/lincke/tagp. Accessed 26 June 2012
Lincke, D.: A transformational approach to generic software development based on higher-order, typed (HOT) functional signatures. PhD thesis, Technical University Hamburg-Harburg (2012)
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)
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)
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)
McNamara B.: Multiparadigm programming: novel devices for implementing functional and logic programming constructs in C++. PhD thesis, Georgia Institute of Technology (2004)
Stepanov, A.A., Lee, M.: The Standard Template Library. Technical report X3J16/94-0095, WG21/N0482 (1994)
Sommerville, I.: Software Engineering. Addison-Wesley, Amsterdam (2006)
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)
Vandervoorde, D., Josuttis, N.M.: C++ Templates: The Complete Guide. Addison-Wesley, Amsterdam (2002)
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)
Zalewski, M.: Generic Programming with Concepts. PhD thesis, Chalmers University of Technology, Gothenburg (2008)
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)
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
Corresponding author
Rights 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
Published:
Issue Date:
DOI: https://doi.org/10.1007/s10009-014-0299-0