[go: up one dir, main page]
More Web Proxy on the site http://driver.im/ skip to main content
10.1145/2364394.2364400acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

Using functional languages to facilitate C++ metaprogramming

Published: 12 September 2012 Publication History

Abstract

Template and Preprocessor Metaprogramming are both well-known in the C++ community to have much in common with Functional Programming (FP). Recently, very few research threads on underpinning these commonalities have emerged to empower cross-development of C++ Metaprogramming (C++MP) and FP. In this paper, we program a self-contained real-world example in a side-by-side fashion to explore the usefulness of a few mainstream FP languages for this purpose: We develop a compile-time abstract datatype for Rational Numbers in C++. We then present the runtime equivalent in HASKELL, F#, and Scala to discuss some FP parallels across the languages. Here, we consider semi-automatic translation between C++MP and FP languages, for earlier studies on these parallels have already obviated the impracticability of fully automatic translations. Our study also shows the superiority of multiparadigm FP languages over single-paradigm ones. In particular, we conclude Scala to currently be the most promising FP language for facilitating C++MP.

References

[1]
International Standard ISO/IEC 14882:1998(E): Programming languages - C++, (1998).
[2]
International Standard ISO/IEC 14882:2011: Information technology - Programming languages - C++, (2011).
[3]
D. Abrahams and A. Gurtovoy, C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond (C++ in Depth Series), AW Prof., 2004.
[4]
M. H. Austern, Generic Programming and the STL: Using and Extending the C++ Standard Template Library, AWProf. Comp. Series, AW Longman Publ. Co., 1998.
[5]
W. Brown, A Preliminary Proposal for a Static if, WG21/N3322 = PL22.16/12-0012.
[6]
M. Calabrese, Boost.generic: Concepts without concepts, BoostCon 2011, http://boostcon.boost.org/program/sessions/.
[7]
D. Gregor, J. Järvi, J. Siek, B. Stroustrup, G. Dos Reis, and A. Lumsdaine, Concepts: Linguistic Support for Generic Prog. in C++, OOPSLA '06: Proc. 21st annual ACM SIGPLAN conf. Object-oriented prog. systems, langs., and applications (New York, NY, USA), ACM Press, 2006, pp. 291--310.
[8]
D. Lincke and S. Schupp, From HOT to COOL: Transforming Higher-Order Typed Languages to Concept-Constrained Object-Oriented Languages, LDTA 2012: Proc. 12th Int.W. Lang. Descriptions, Tools, and Appl., 2012, pp. 17--30.
[9]
J. Gibbons, Datatype-Generic Prog., Spring School on Datatype-Generic Prog. (R. Backhouse, J. Gibbons, R. Hinze, and J. Jeuring, eds.), LNCS, vol. 4719, Springer-Verlag, 2007, pp. 1--72.
[10]
S. Golodotz, Functional Programming Using C++ Templates (Part 1), Overload J. #81, http://accu.org/index.php/journals/1422.
[11]
A. Gurtovoy and D. Abrahams, The Boost C++ Meta-Prog. Library, http://www.boost.org/.
[12]
J. de Guzman, D. Marsden, and T. Schwinger, Boost Fusion Library: Library for working with tuples, including various containers, algorithms, etc., http://www.boost.org/.
[13]
A. Lumsdaine J. Järvi, J. Willcock and M. Calabrese, Boost Ratio Library: Enable If, http://www.boost.org/.
[14]
J. P. Bernardy, P. Jansson, M. Zalewski, S. Schupp, and A. Priesnitz, A Comparison of C++ Concepts and HASKELL Type Classes, Proc. ACM SIGPLAN W. Generic Prog. (New York, NY, USA), WGP '08, ACM, 2008, pp. 37--48.
[15]
V. Karvonen and P. Mensonides, The Boost Library, Preprocessor Subset for C/C++, http://www.boost.org/.
[16]
J. Launchbury, A natural semantics for lazy evaluation, POPL '93: Proc. 20th ACM SIGPLAN-SIGACT Symp. Principles of Prog. Lang., ACM, 1993, pp. 144--154.
[17]
M. Zalewski, A. Priesnitz, C. Ionescu, N. Botta, and S. Schupp, Multi-language Library Development: From HASKELL Type Classes to C++ Concepts, Multiparadigm Prog. with Object-Oriented Lang., an ECOOP W., 2007.
[18]
Microsoft, Rational Structure, Microsoft Solver Foundation 3.0, http://msdn.microsoft.com/en-us/library/microsoft.solverfoundation.common.rational(v=vs.93).aspx#Y0.
[19]
B. Milewski, Bartosz Milewski's Prog. Cafe: Concurrency, Multicore, C++, Haskell, http://bartoszmilewski.wordpress.com/.
[20]
E. Moggi, Notions of Computation and Monads, Inf. & Comp. 93 (1991), no. 1, 55--92.
[21]
E. Niebler, Boost Proto Library: Expression template library and compiler construction toolkit for domain-specific embedded langs., http://www.boost.org/.
[22]
P. Moore, Boost Rational Library: A rational number class, http://www.boost.org/.
[23]
R. Plasmeijer and M. van Eekelen, Concurrent CLEAN Language Report (v 2.0), Dec 2001, http://www.cs.kun.nl/~clean/contents/contents.html.
[24]
R. Garcia and A. Lumsdaine, Toward Foundations for Type-Reflective Metaprogramming, ACM SIGPLAN Notices 45 (2010), no. 2, 25--34.
[25]
D. Sankel, Algebraic Data Types Series, C++Next: The next generation of C++, http://cpp-next.com/archive/2010/07/algebraic-data-types/.
[26]
S. H. HAERI, Observational Equivalence and a New Operational Semantics for Lazy Evaluation with Selective Strictness, Proc. Int. Conf. Theoretical and Math. Foundations of Comp. Sci. (TMFCS-10), 2010.
[27]
S. H. HAERI and S. Schupp, Functional Metaprogramming in C++ and Cross-Lingual Development with HASKELL, Tech. report, Uni. Kansas, Oct 2011, Draft Proc. 23rd Symp. Impl. and Appl. Func. Langs., ITTC-FY2012-TR-29952012-01.
[28]
Á. Sinkovics, Funcional Extensions to the Boost Metaprogram Library, Proc. 2nd Works. Generative Tech., Elec. Notes in Theo. Comp. Sci., vol. 264, Jul 2011, pp. 85--101.
[29]
_____, Nested Lamda Expressions with Let Expressions in C++ Template Metaprograms, WGT'11 (Z. Porkoláb and N. Pataki, eds.), vol. III, Zolix, 2011, pp. 63--76.
[30]
Á. Sinkovics and Z. Porkoláb, Expressing C++ Template Metaprograms as Lambda Expressions, TFP (Z. Horváth, V. Zsók, P. Achten, and P. Koopman, eds.), Trends in Func. Prog., vol. 10, Intellect, UK/The Uni. Chicago Press, USA, June 2-4 2009, pp. 1--15.
[31]
Á. Sipos, Z. Porkoláb, N. Pataki, and V. Zsók, Meta Fun: Towards a Functional-Style Interface for C++ Template Metaprograms, Tech. report, Eötvös Loránd Uni, Fac. of Inf., Dept. Prog. Langs., Pázmány Péter sétány 1/C H-1117 Budapest, Hungary, 2007.
[32]
E. Unruh, Prime Number Computation, 1994, ANSI X3J16-94-0075/ISO WG21-462.
[33]
M. van Eekelen and M. de Mol, Mixed lazy/strict graph semantics, Impl. and Appl. of Func. Langs., 16th Int. W., IFL04 (Lüebeck, Germany) (C. Grelck and F. Huch, eds.), Tech. Rep. 0408, Christian-Albrechts-Universität zu Kiel, September 2004, pp. 245--260.
[34]
T. Veldhuizen, Expression Templates, C++ Report 7 (1995), no. 5, 26--31.
[35]
V. J. Botet Escribá, Boost Ratio Library: Compile time rational arithmetic, http://www.boost.org/.
[36]
W. Bright, H. Sutter, and A. Alexandrescu, Proposal: static if declaration, JTC1/SC22/WG21 N3329.
[37]
W. Miao and J. Siek, Incremental Type-Checking for Type-Reflective Metaprograms, ACM SIGPLAN Notices 46 (2011), no. 2, 167--176.
[38]
Z. Porkoláb and Á. Sinkovics, C++ Template Metaprogramming with Embedded Haskell, Proc. 8th Int. Conf. Generative Prog. & Component Engineering (GPCE 2009) (New York, NY, USA), ACM, 2009, pp. 99--108.

Cited By

View all
  • (2019)Intrinsic Currying for C++ Template MetaprogramsTrends in Functional Programming10.1007/978-3-030-18506-0_3(46-73)Online publication date: 24-Apr-2019

Index Terms

  1. Using functional languages to facilitate C++ metaprogramming

    Recommendations

    Comments

    Please enable JavaScript to view thecomments powered by Disqus.

    Information & Contributors

    Information

    Published In

    cover image ACM Conferences
    WGP '12: Proceedings of the 8th ACM SIGPLAN workshop on Generic programming
    September 2012
    92 pages
    ISBN:9781450315760
    DOI:10.1145/2364394
    Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

    Sponsors

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 12 September 2012

    Permissions

    Request permissions for this article.

    Check for updates

    Author Tags

    1. c++ metaprogramming
    2. cross-lingual development
    3. f#
    4. functional programming
    5. haskell
    6. scala

    Qualifiers

    • Research-article

    Conference

    ICFP'12
    Sponsor:

    Acceptance Rates

    Overall Acceptance Rate 30 of 43 submissions, 70%

    Upcoming Conference

    ICFP '25
    ACM SIGPLAN International Conference on Functional Programming
    October 12 - 18, 2025
    Singapore , Singapore

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)3
    • Downloads (Last 6 weeks)0
    Reflects downloads up to 18 Dec 2024

    Other Metrics

    Citations

    Cited By

    View all
    • (2019)Intrinsic Currying for C++ Template MetaprogramsTrends in Functional Programming10.1007/978-3-030-18506-0_3(46-73)Online publication date: 24-Apr-2019

    View Options

    Login options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Media

    Figures

    Other

    Tables

    Share

    Share

    Share this Publication link

    Share on social media