You are not logged in.

#1 2008-05-12 09:13:01

wuischke
Member
From: Suisse Romande
Registered: 2007-01-06
Posts: 630

An old love may have returned... (functional C++)

After discovering functional programming languages (and Italian), programming in C++ became dull and boring and was not fun anymore, as it used to be. It got so bad, that I started to learn JavaScript and DOM (I hate client side web programming and web design in general.) because I couldn't get myself to implement it in Cpp...but now I've found something which might make me fall in love in again.

It's like a dream come true: The good things about C++ combined with wath I love about functional programming: FC++: Functional Programming in C++

Has anyone made experience with this library? It sound really cool and bending my mind (favourite hobby when using functional programming languages) might return to C++ instead of writing endless boring lines of code without any actual relevance to the algorithm.

Offline

#2 2008-05-12 10:02:45

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,384
Website

Re: An old love may have returned... (functional C++)

I have no experience with this but I am a bit confused as to its purpose...

Functional programming is a programming paradigm in which functions are treated as regular values. Thus, we can have functions that take other functions as parameters.

Can't you already do that with pointers to functions?  Anyway, I am probably missing something obvious and am actually going to spend some time reading up on this now....

Offline

#3 2008-05-12 11:59:16

Bison
Member
From: Jacksonville, FL
Registered: 2006-04-12
Posts: 158
Website

Re: An old love may have returned... (functional C++)

Whats wrong with just using haskell or clean?

Offline

#4 2008-05-12 12:03:18

Misery
Member
Registered: 2008-04-10
Posts: 41

Re: An old love may have returned... (functional C++)

Maybe D is right for you... ;-)
http://en.wikipedia.org/wiki/D_(programming_language) ... I like some ideas there.

Last edited by Misery (2008-05-12 12:03:49)

Offline

#5 2008-05-12 13:27:49

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: An old love may have returned... (functional C++)

Bison wrote:

Whats wrong with just using haskell or clean?

Misery wrote:

Maybe D is right for you... ;-)

The original question was "has anyone had any experience with FC++?" - not "please recommend me a functional language" - and your responses do not help answer that question at all.  Please keep on topic.

Offline

#6 2008-05-12 13:42:50

kakTuZ
Member
From: Hannover, Germany
Registered: 2007-10-20
Posts: 86

Re: An old love may have returned... (functional C++)

Hi, I have been coding with c++ for years now. A month ago i started learning Haskell (had Scheme -- a lisp dialect -- in University, so functional programing is not that new to me) and recently i was thinking, that it would be cool to have things like map and fold in c++. Thanks for the link

Offline

#7 2008-05-12 22:39:37

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: An old love may have returned... (functional C++)

Allan wrote:

I have no experience with this but I am a bit confused as to its purpose...

Functional programming is a programming paradigm in which functions are treated as regular values. Thus, we can have functions that take other functions as parameters.

Can't you already do that with pointers to functions?  Anyway, I am probably missing something obvious and am actually going to spend some time reading up on this now....

Yes-ish. But you can't create new functions at run-time, or have anonymous functions. Functional programming isn't just first-class functions though. It's programming by applying functions to other functions rather than creating a bunch of temporary variables or modifying state stored in variables.

IME, the only thing more painful than coding in C++ is coding something fancy in C++, so I'm out of here rather than straying off topic some more.

Offline

#8 2008-05-13 08:11:18

wuischke
Member
From: Suisse Romande
Registered: 2007-01-06
Posts: 630

Re: An old love may have returned... (functional C++)

Thanks for your answers.

Allan: I previously failed when I wanted to achieve some things using function pointers. It's a bit embarrassing, but I simply gave up, because things which are very simple in functional programming languages turned out to be a lot more complicated in C++. Namely I wanted to get rid of certain loops in my code and compress it to an one liner. But in the end it was simpler to keep the loops, because it required a lot less work and I had other things to do. Template metaprogramming, btw, turned out to be useless for my usage cases, too. sad

Bison: With Clean: multi-platform support. With Haskell: Absolutely nothing, but I'm not ready yet and focus on learning Erlang properly first.

Misery: Tried D 1.0, liked it, but switched back to C++ due to lack of supported platforms. Situation hasn't improved afaik.

Paul Donnelly: I was afraid someone would say that, because I got the same impression. I rather began enjoying coding in JavaScript anyway (after stopping to worry about cross-browser-compatibility at least) and will better spend my time on learning Erlang to the level, where I can do all things I know how to do in C++ in Erlang as well, instead of wasting more time on getting back to C++.

Offline

#9 2008-05-13 08:24:49

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,384
Website

Re: An old love may have returned... (functional C++)

wuischke wrote:

Allan: I previously failed when I wanted to achieve some things using function pointers. It's a bit embarrassing, but I simply gave up, because things which are very simple in functional programming languages turned out to be a lot more complicated in C++. Namely I wanted to get rid of certain loops in my code and compress it to an one liner. But in the end it was simpler to keep the loops, because it required a lot less work and I had other things to do. Template metaprogramming, btw, turned out to be useless for my usage cases, too. sad

That may be why I missed the point a bit here.  I tend to use combinations of template metaprogramming and function pointers in some of my backend/library code.  Never in the main program because it is too complicated to easily follow and I believe anything that complicated should be hidden in a library...  I read up on it a bit more and it sounds quite interesting.  I noticed that wikipedia states that R (statistics package) is a functional programming language.  Much of my C++ work has been geared towards making a library that allows for the ease of analysis provided in R with the speed of highly optimized C++.  I guess I have been trying to do functional programming without knowing what it was!

Offline

#10 2008-05-13 08:29:59

wuischke
Member
From: Suisse Romande
Registered: 2007-01-06
Posts: 630

Re: An old love may have returned... (functional C++)

I had to laugh: http://en.wikipedia.org/wiki/Greenspun%27s_Tenth_Rule wink

Functional programming languages (particularly the above mentioned Haskell and Clean, but OCaml, too) are in many cases comparable to the speed achieved with C++ and in some cases even a lot faster.

Offline

#11 2008-05-13 09:30:04

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,384
Website

Re: An old love may have returned... (functional C++)

Not R...  as soon as you loop it becomes slow as a tortoise!  A very slow tortoise.

Last edited by Allan (2008-05-13 09:42:40)

Offline

#12 2008-05-13 13:06:58

Bison
Member
From: Jacksonville, FL
Registered: 2006-04-12
Posts: 158
Website

Re: An old love may have returned... (functional C++)

Personally, I don't understand why you would use an imperative language to write in a functional style (unless you have to use a certain language).  If you want to program in the functional style, you should use a language that is intended for it.

Offline

Board footer

Powered by FluxBB