问题
Java has Scala and .NET has F#. Both of these languages are very highly integrated into the respective Java and .NET platforms. Classes can be written in Scala then extended in Java for example.
Does there exist an equivalent functional language that interoperates highly with C++?
回答1:
The Felix language by John Skaller is designed to interoperate with C++ and provide the functional paradigm.
There are problems with doing this though. Functional languages provide first-class functions which allow the creation of closures: functions that have captured and carry values from the environment they were defined in. This makes it impossible to determine the lifetimes of values statically (because a closure might carry a value out of its scope) and, consequently, effectively requires a garbage collector but C++ is not garbage collected.
回答2:
C++ doesn't have an ecosystem in the sense of Java or .NET. There's no virtual machine, no runtime environment even, there's only a highly specialized standard library that by design doesn't operate well in a purely functional environment. C++ doesn't even have an ABI standard.
All things considered, I'm not sure what you mean/expect.
回答3:
Ah, something else. Although this certainly isn't what you meant, template metaprogramming in C++ is purely functional.
回答4:
As has been said, I'm not really sure about a C++ 'ecosystem'. But Haskell does have a Foreign Function Interface that allows you to call C functions from Haskell and Haskell functions from C.
Then again, that's C, I'm not really sure how far along the C++ FFI is...
回答5:
Since Scala compiles into Java bytecode and F# compiles into .NET bytecode, made to run on their respective virtual machines. The correct comparison would be if there is some functional language that compile to machine dependant code, ready to run on a computer, and yes, there are.
I don't think that was what you meant though, but the best I have to offer is FC++. Boost is another library which has a lot of features that can be recognized as derived from functional programming.
However, I'd wager there are no 'real' functional programming C++:es out there.
回答6:
The 'D' language was designed as a successor to C++. A purely functional subset of D is being developed by Andrei Alexandrescu for D 2.0. I am guessing D interoperates well with C++.
回答7:
I agree that I am not sure of an ecosystem for C++. OCaml is pretty popular for doing functional programming outside of .NET. F# is also based off of it.
回答8:
This question was posted in 2008. For reference, C++11 onwards have support for functional programming. See another discussion updated for this Functional Programming in C++
回答9:
C++ may not be a pure functional language, but parts of STL are certainly functional.
See Bjarne Stroustrup FAQ (the inventor of the c++)
来源:https://stackoverflow.com/questions/24995/is-there-a-functional-language-for-c-ecosystem