Living with Lambdas -- Alfons Haffmans

living-with-lambdas.PNGWe have such a powerful language, and what a powerful language it is.

Living with Lambdas

by Alfons Haffmans

From the article:

You can work in the functional programming paradigm in C++. And you may be surprised at how complete C++’s support for functional programming is.

... C++ has always been a multi-paradigm language. And while previous attempts to add practical functional programming features required significant effort, recent additions to the C++ standard, like lambdas, have improved the situation. This paper explores the out-of-box support for functional programming provided by the new standard. We’ll look at techniques typically found in introductory functional programming textbooks. This article assumes familiarity with C++, but not necessarily with basic functional programming.

The source code is available in github and is compiled using gcc 4.8 installed on Mac OSX using MacPorts.

Add a Comment

Comments are closed.

Comments (1)

3 0

R. Martinho Fernandes said on Jul 8, 2013 07:01 AM:

I'll put aside my disagreements with the premise of the article that C++’s support for functional programming is quite complete, and just mention the non-technical reasons why I did not like the article.

The article goes on to show us things in various places, and uses sentences ending with a colon to introduce the thing being shown. All good, except for the fact that the thing being shown is nowhere to be seen after the colon. I see nothing after "Here’s the type signature of the identity function:", for example; I also only see one "implementation" of `id` after "Here are two implementations of id:". Oh, yeah, that "implementation" of `id`...

Then, the article claims to be using Haskell's notation for function signatures, but then goes on to use some weird hybrid of Haskell and C++ notation in things like "id (int x) ::int = x". I don't have a problem with understanding either Haskell or C++ function signatures, but I certainly have a problem with understanding something that is *neither*.

I more or less gave up on it soon after that. I find the style with spaces around :: and < a bit of an eyesore but that's a personal stylistic issue. What isn't a personal stylistic issue is something like "map(op, std :: forward list<int >({1,?6,23,78,45,13}));", which doesn't even compile... Or completely bogus signatures like "std :: forward list<std :: tuple<A,B>> zip (const std :: forward list< A>&L, const std :: forward list<B>&M)"... What in the seven hells is that?

I could rant on about the abuse of `std::function` in template functions, or about creating new instances of containers all over the place instead of iterators, or simply about how unwieldy it is to actually make use of this thing in non-toy code, but I'll leave it at the issues that prevented me from even enjoying the act of reading the article.