Intrinsic currying for C++ template metaprograms

Paul Keir, Andrew Gozillon, Seyed H. Haeri (Hossein)

Research output: Chapter in Book/Report/Conference proceedingConference contribution

5 Downloads (Pure)

Abstract

C++ template metaprogramming is a form of strict functional programming, with a notable absence of intrinsic support for elementary higher-order operations. We describe a variadic template metaprogramming library which offers a model of implicitly curried, left-associative metafunction application through juxtaposition; inspired by languages such as Haskell, OCaml and F#. New and existing traits and metafunctions, constructed according to conventional idioms, seemlessly take advantage of the framework's features. Furthermore, a distinctive versatility is exposed, allowing a user to define higher-order metafunction classes using an equational definition syntax; without recourse to elaborate nested metafunctions. The primary type expression evaluator of the library is derived from a single application of an elementary folding combinator for type lists. The definition of the fold's binary operator argument is therefore a focal point; and constructed mindful that substitution failure of a template parameter's deduced type produces no compilation error. Two distinctive features of C++ metafunctions require particular consideration: zero argument metafunctions; and variadic metafunctions. We conclude by demonstrating characteristics of the library's main evaluation metafunction in conjunction with the universal property of an updated right-fold combinator, to compose a range of metafunctions including map, reverse, left-fold, and the Ackermann function.
Original languageEnglish
Title of host publicationTrends in Functional Programming
Subtitle of host publication19th International Symposium, TFP 2018 Gothenburg, Sweden, June 11–13, 2018 Revised , Sweden, June 11-13, Selected Papers
PublisherSpringer International Publishing AG
Pages46-73
Number of pages28
ISBN (Electronic)9783030185060
ISBN (Print)9783030185053
DOIs
Publication statusPublished - 24 Apr 2019

Publication series

NameLecture Notes in Computer Science
PublisherSpringer International Publishing
ISSN (Print)0302-9743
ISSN (Electronic)1611-3349

Fingerprint

recourse
substitution
syntax
programming
language
evaluation

Keywords

  • Currying
  • Metaprogramming
  • Templates
  • Types

Cite this

Keir, P., Gozillon, A., & Haeri (Hossein), S. H. (2019). Intrinsic currying for C++ template metaprograms. In Trends in Functional Programming: 19th International Symposium, TFP 2018 Gothenburg, Sweden, June 11–13, 2018 Revised , Sweden, June 11-13, Selected Papers (pp. 46-73). (Lecture Notes in Computer Science). Springer International Publishing AG. https://doi.org/10.1007/978-3-030-18506-0_3
Keir, Paul ; Gozillon, Andrew ; Haeri (Hossein), Seyed H. / Intrinsic currying for C++ template metaprograms. Trends in Functional Programming: 19th International Symposium, TFP 2018 Gothenburg, Sweden, June 11–13, 2018 Revised , Sweden, June 11-13, Selected Papers. Springer International Publishing AG, 2019. pp. 46-73 (Lecture Notes in Computer Science).
@inproceedings{3d4950c8a4f94d189b50eecbfd6cfbdd,
title = "Intrinsic currying for C++ template metaprograms",
abstract = "C++ template metaprogramming is a form of strict functional programming, with a notable absence of intrinsic support for elementary higher-order operations. We describe a variadic template metaprogramming library which offers a model of implicitly curried, left-associative metafunction application through juxtaposition; inspired by languages such as Haskell, OCaml and F#. New and existing traits and metafunctions, constructed according to conventional idioms, seemlessly take advantage of the framework's features. Furthermore, a distinctive versatility is exposed, allowing a user to define higher-order metafunction classes using an equational definition syntax; without recourse to elaborate nested metafunctions. The primary type expression evaluator of the library is derived from a single application of an elementary folding combinator for type lists. The definition of the fold's binary operator argument is therefore a focal point; and constructed mindful that substitution failure of a template parameter's deduced type produces no compilation error. Two distinctive features of C++ metafunctions require particular consideration: zero argument metafunctions; and variadic metafunctions. We conclude by demonstrating characteristics of the library's main evaluation metafunction in conjunction with the universal property of an updated right-fold combinator, to compose a range of metafunctions including map, reverse, left-fold, and the Ackermann function.",
keywords = "Currying, Metaprogramming, Templates, Types",
author = "Paul Keir and Andrew Gozillon and {Haeri (Hossein)}, {Seyed H.}",
note = "Approved for publication 30/11/2018. Accepted author manuscript uploaded 01/02/2019.",
year = "2019",
month = "4",
day = "24",
doi = "10.1007/978-3-030-18506-0_3",
language = "English",
isbn = "9783030185053",
series = "Lecture Notes in Computer Science",
publisher = "Springer International Publishing AG",
pages = "46--73",
booktitle = "Trends in Functional Programming",
address = "Switzerland",

}

Keir, P, Gozillon, A & Haeri (Hossein), SH 2019, Intrinsic currying for C++ template metaprograms. in Trends in Functional Programming: 19th International Symposium, TFP 2018 Gothenburg, Sweden, June 11–13, 2018 Revised , Sweden, June 11-13, Selected Papers. Lecture Notes in Computer Science, Springer International Publishing AG, pp. 46-73. https://doi.org/10.1007/978-3-030-18506-0_3

Intrinsic currying for C++ template metaprograms. / Keir, Paul; Gozillon, Andrew; Haeri (Hossein), Seyed H.

Trends in Functional Programming: 19th International Symposium, TFP 2018 Gothenburg, Sweden, June 11–13, 2018 Revised , Sweden, June 11-13, Selected Papers. Springer International Publishing AG, 2019. p. 46-73 (Lecture Notes in Computer Science).

Research output: Chapter in Book/Report/Conference proceedingConference contribution

TY - GEN

T1 - Intrinsic currying for C++ template metaprograms

AU - Keir, Paul

AU - Gozillon, Andrew

AU - Haeri (Hossein), Seyed H.

N1 - Approved for publication 30/11/2018. Accepted author manuscript uploaded 01/02/2019.

PY - 2019/4/24

Y1 - 2019/4/24

N2 - C++ template metaprogramming is a form of strict functional programming, with a notable absence of intrinsic support for elementary higher-order operations. We describe a variadic template metaprogramming library which offers a model of implicitly curried, left-associative metafunction application through juxtaposition; inspired by languages such as Haskell, OCaml and F#. New and existing traits and metafunctions, constructed according to conventional idioms, seemlessly take advantage of the framework's features. Furthermore, a distinctive versatility is exposed, allowing a user to define higher-order metafunction classes using an equational definition syntax; without recourse to elaborate nested metafunctions. The primary type expression evaluator of the library is derived from a single application of an elementary folding combinator for type lists. The definition of the fold's binary operator argument is therefore a focal point; and constructed mindful that substitution failure of a template parameter's deduced type produces no compilation error. Two distinctive features of C++ metafunctions require particular consideration: zero argument metafunctions; and variadic metafunctions. We conclude by demonstrating characteristics of the library's main evaluation metafunction in conjunction with the universal property of an updated right-fold combinator, to compose a range of metafunctions including map, reverse, left-fold, and the Ackermann function.

AB - C++ template metaprogramming is a form of strict functional programming, with a notable absence of intrinsic support for elementary higher-order operations. We describe a variadic template metaprogramming library which offers a model of implicitly curried, left-associative metafunction application through juxtaposition; inspired by languages such as Haskell, OCaml and F#. New and existing traits and metafunctions, constructed according to conventional idioms, seemlessly take advantage of the framework's features. Furthermore, a distinctive versatility is exposed, allowing a user to define higher-order metafunction classes using an equational definition syntax; without recourse to elaborate nested metafunctions. The primary type expression evaluator of the library is derived from a single application of an elementary folding combinator for type lists. The definition of the fold's binary operator argument is therefore a focal point; and constructed mindful that substitution failure of a template parameter's deduced type produces no compilation error. Two distinctive features of C++ metafunctions require particular consideration: zero argument metafunctions; and variadic metafunctions. We conclude by demonstrating characteristics of the library's main evaluation metafunction in conjunction with the universal property of an updated right-fold combinator, to compose a range of metafunctions including map, reverse, left-fold, and the Ackermann function.

KW - Currying

KW - Metaprogramming

KW - Templates

KW - Types

U2 - 10.1007/978-3-030-18506-0_3

DO - 10.1007/978-3-030-18506-0_3

M3 - Conference contribution

SN - 9783030185053

T3 - Lecture Notes in Computer Science

SP - 46

EP - 73

BT - Trends in Functional Programming

PB - Springer International Publishing AG

ER -

Keir P, Gozillon A, Haeri (Hossein) SH. Intrinsic currying for C++ template metaprograms. In Trends in Functional Programming: 19th International Symposium, TFP 2018 Gothenburg, Sweden, June 11–13, 2018 Revised , Sweden, June 11-13, Selected Papers. Springer International Publishing AG. 2019. p. 46-73. (Lecture Notes in Computer Science). https://doi.org/10.1007/978-3-030-18506-0_3