views:

523

answers:

3

I've been looking at the new features in c++0x 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++0x template. It looks like microsoft is trying to do that with their STL Algorithm class. What problems of advantages do you see in using c++0x vs something like f# for a mixed functional programming style? Maybe the Boost guys will make a new functional once c++0x comes out.

A: 

I imagine that it would be… interesting… to implement certain optimizations common to functional languages in C++0x (like common subexpression elimination).

John Calsbeek
Most C and C++ compilers do CSE and GCSE. This is not the problem. The problem involves partial function application and tail recursion.
Christopher
+10  A: 

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.

Christopher
+5  A: 

You might find this interesting:

http://smellegantcode.wordpress.com/2009/01/26/linq-to-c0x/

Daniel Earwicker
Ooh, interesting indeed. Nice work.
jalf
Thanks! A starting point for a full implementation would be boost's range and iterator libraries, some combination of the two.
Daniel Earwicker