Reputation: 13862
I've been looking at the new features in C++11 and it really looks like it will be possible to program in a very functional programming style using it. I've gotten use to using the types List, Seq, Array in F# and I see no reason why their members couldn't be ported into some sort of C++11 template. What problems or advantages do you see in using C++11 vs something like F# for a mixed functional programming style? Maybe the Boost guys will make a new functional
once C++11 comes out.
Upvotes: 10
Views: 4110
Reputation: 2380
Here are some of the problems I encountered trying to write functional code in C#, mixed with some goodies from my time when I was still using C++:
It would not surprise me if several of these points were actually possible in C++ using some template and preprocessor magic, but you can't really use these in a production environment unless you have very adventurous and tolerant co-workers.
I was a die-hard C++ enthusiast before. Then I started using generic programming with templates and higher-order functions using function objects. It just was too tiresome to write. After I tried a functional language I never looked back.
Upvotes: 6
Reputation: 48687
What problems of advantages do you see in using c++0x vs something like f# for a mixed functional programming style?
The upward funarg problem, which was debated in the context of Lisp 40 years ago!
Upvotes: 3
Reputation: 116664
You might find this interesting:
http://smellegantcode.wordpress.com/2009/01/26/linq-to-c0x/
Upvotes: 5
Reputation: 9084
The biggest problem with trying to program in a functional style in C++ is that it does not support tail recursion. In a functional language you don't have to worry about stack explosion when you tail recurse correctly, but in C++ you always have to worry about that. Therefore, many "functional" type algorithms will be clumsy or heavy.
Upvotes: 15
Reputation: 36497
I imagine that it would be… interesting… to implement certain optimizations common to functional languages in C++0x (like common subexpression elimination).
Upvotes: 0