Abstract
Graham Hutton’s 1999 monograph: A tutorial on the universality and expressiveness of fold provides a fascinating and eminently readable analysis of an elementary reduction operator from functional programming: fold. Hutton’s tutorial is punctuated by increasingly compelling examples, written in Haskell, of the use of fold to implement common list operations, including summation; concatenation; reversal; function composition; left folds; and concluding with the Ackermann function. The fold combinator is directly comparable to the C++ standard library function: std::accumulate. In this article, I focus on the fold examples from Hutton, and present equivalent generic C++ incarnations of each; making thorough use of appropriate C++14 library and language features, including polymorphic lambda functions
Original language | English |
---|---|
Article number | 2182 |
Pages (from-to) | 13-15 |
Number of pages | 3 |
Journal | Overload |
Issue number | 130 |
Publication status | Published - Dec 2015 |
Keywords
- fold
- catamorphism
- C++
- ackermann
- accumulate