Re:Bartosz Milewski - The Downfall of Imperative Programming
by 16s on Monday April 09, 2012 @03:11PM
(#3818675)
I'd like to be able to use C++ in a purely functional manner rather than use Haskell, etc. Has anyone done that, if so, what was it like?
[ Parent
| on HN ]
Re:Bartosz Milewski - The Downfall of Imperative Programming
by ajax77 on Monday April 09, 2012 @04:29PM
(#3819074)
With the niceties of C++11, it's certainly become a lot less painful; lambdas, auto (both variable and return type), variadic templates and r-value references give the language just enough flexibility to allow functional style with far more natural syntax. To be sure, it's not a perfect setup; type traits (e.g., enable_if) in function signatures are ugly and hardly a replacement for concepts.
I've been dabbling in the creation of a functional library that provides a modest subset of Prelude-inspired features from Haskell. https://github.com/jdduke/fpcpp Many of the algorithms are simply wrappers around stl algorithms, hiding some of the syntactic awkwardness attendant with the heavy use of iterators. Some day I'll get around to playing with monadic devices, and integrating the list comprehension work that I've done recently.
Re:Bartosz Milewski - The Downfall of Imperative Programming
by hristov on Monday April 09, 2012 @03:35PM
(#3818797)
You can if you want to. Just make sure you write all your functions in a purely functional way, and avoid all side effects.
You do not really need changes to the language, just iron discipline.
Re:Bartosz Milewski - The Downfall of Imperative Programming
by ttt_ on Monday April 09, 2012 @03:48PM
(#3818862)
>> just iron discipline
That's where it gets tricky. It's hard enough dealing with your own discipline ironing, imagine a dev team composed of varied expertise and awareness levels.
Re:Bartosz Milewski - The Downfall of Imperative Programming
by swalsh on Monday April 09, 2012 @05:28PM
(#3819330)
imagine the dev team who takes over the project after you leave. Iron discipline doesn't exist over long periods of time, that's why it needs to be built into the language.
Re:Bartosz Milewski - The Downfall of Imperative Programming
by eli_gottlieb on Monday April 09, 2012 @03:32PM
(#3818782)
One of my undergraduate mentors wrote a library called FC++.