views:

984

answers:

8

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++?

+4  A: 

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.

Konrad Rudolph
The reason I landed onto this question is looking for a concise-to-use (i.e. minimal lines of human-understandable code) language with C++.
Amit Kumar
+1  A: 

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.

Henrik Gustafsson
+6  A: 

Ah, something else. Although this certainly isn't what you meant, template metaprogramming in C++ is purely functional.

Konrad Rudolph
+1  A: 

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...

Tom Lokhorst
A: 

C++ may not be a pure functional language, but parts of STL are certainly functional.

See Bjarne Stroustrup FAQ (the inventor of the c++)

vzczc
Not really: C++ does not have first-class functions with automatic environment capture. What you are referring to is grindingly tedious and far less expressive.Also, Bjarne Stroustrup and Alex Stepanov are generally completely wrong when it comes to functional programming.
Jon Harrop
C++0x does have first-class functions with automatic environment capture in form of lambdas, though with the usual C++ resource management caveats apply (because of lack of GC).
Pavel Minaev
+2  A: 

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++.

Andy Brice
D actually does not work well with C++. You almost always have to write C wrappers.
Zifre
+2  A: 

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.

Dale Ragan
+5  A: 

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.

Cheers, Jon Harrop.

Jon Harrop