4 ms·
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?
by 16s 15y ago
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?
- ajax77 15y agoWith 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 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.
- eli_gottlieb 15y agoOne of my undergraduate mentors wrote a library called FC++.
- hristov 15y agoYou 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.
- ttt_ 15y ago>> 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.
- swalsh 15y agoimagine 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.