pauldoo
pauldoo

Reputation: 18635

Is there a functional language for C++ ecosystem?

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

Upvotes: 12

Views: 3616

Answers (9)

J D
J D

Reputation: 48687

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.

Upvotes: 8

Vishal
Vishal

Reputation: 43

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

Upvotes: 0

Dale Ragan
Dale Ragan

Reputation: 18270

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.

Upvotes: 1

Andy Brice
Andy Brice

Reputation: 2317

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

Upvotes: 3

vzczc
vzczc

Reputation: 9380

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

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

Upvotes: -1

Tom Lokhorst
Tom Lokhorst

Reputation: 13768

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

Upvotes: 6

Konrad Rudolph
Konrad Rudolph

Reputation: 545865

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

Upvotes: 8

Henrik Gustafsson
Henrik Gustafsson

Reputation: 54228

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.

Upvotes: 3

Konrad Rudolph
Konrad Rudolph

Reputation: 545865

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.

Upvotes: 8

Related Questions