Live data from Hacker News

Functional Programming with Java

functionaljava.org

11–20 of 30 posts

Re: Functional Programming with Java

#11

Or even better than using libraries for functional programming in Java, learn and use Scala. You can mix Scala and Java code where needed.

scala != functional programming http://enfranchisedmind.com/blog/posts/scala-not-functional/

It does have functional programming constructs though

Clojure is a much better candidate for FP on the JVM.

Re: Functional Programming with Java

#12

Earlier quoted context omitted.

F# doesn't in fact make use of {co|contra}variance: it only needed generics. (Although F# used to run on .NET 1.x using its own implementation of generics - Don Syme designed both .NET generics and the F# language.) For type inference, you just need a sufficiently smart compiler, although it's much more useful if your language knows about generic types.

Thanks for clearing that up (I've yet to try F# in anger). I suppose pre-generics F# did similar type wrangling to Scala's?

I don't know about Scala, but yes, wrangling describes well what F# used to do.

I never used F# before .NET 2.0, but the techniques it used on 1.x could be interesting -- I'll see if I can find some old documentation...

Edit: There used to be a paper describing the technique. I can't find it now, but here's an old Don Syme announcement related to it: http://www.mail-archive.com/dotnet-rotor@discuss.develop.com...

Re: Functional Programming with Java

#13

Or even better than using libraries for functional programming in Java, learn and use Scala. You can mix Scala and Java code where needed.

I second Clojure for a functional programming language on the JVM. Why anyone would want to do functional programming in Java is really beyond my comprehension though.

Re: Functional Programming with Java

#15

Or even better than using libraries for functional programming in Java, learn and use Scala. You can mix Scala and Java code where needed.

scala != functional programming http://enfranchisedmind.com/blog/posts/scala-not-functional/ It does have functional programming constructs though Clojure is a much better candidate for FP on the JVM.

You are right. But scala does not make it any harder if one chooses to write functional code.

Re: Functional Programming with Java

#16
Great Job!!

To those wondering why not move to Clojure or Scala instead of this approach, here is why I am holding back:

a) I have a mission critical enterprise app that is in maintainance mode. I need to enhance certain features dealing with concurrency -- my team can ramp up Actor model implementation in functionaljava or Jetlang faster than they can ramp up on Scala.

b) No doubt that Scala is actually better Java , but I am confident that later versions of JDK would catch up. The concurrency features of JDK 7 are pretty good.

c) did I mention the team -- its hard enough finding a good java programmer; imagine how difficult it would be to hire good Scala programmers from the small eclectic community of Scala programmers.

d) most of the enterprisey stuff my team develops doesn't require functional programming -- just reliable applications delivered within drop dead deadlines. Plain old Java gets me there . JDK 7 concurrency and various Actor model implementations in Java such as FunctionalJava, Jetlang , Kilim are just cherry on top.

Re: Functional Programming with Java

#17
post #7

Earlier quoted context omitted.

final boolean b = a.exists(new F () { public Boolean f(final String s) { return fromString(s).forall(isLowerCase); } }); It's here that I miss lambdas to make functional code at all readable.

exactly the example I was going to cite. In Scala this would be val b = a.exists(str=>str.forall(_.isLowerCase)) or val b = a.exists(x=>x.toLowerCase() == x) There's no way I'd start using functional programming in Java if it's this clunky. Just stick with Scala.

Enumerable.java (http://enumerable.org) is not really a functional library, but it does support limited closures:

boolean b = a.any(λ(s, s.equals(s.toLowerCase()));

s and λ are statically imported.

Re: Functional Programming with Java

#19

Does anybody know if there is a library like this for C/C++?

Take a look at FC++ and Boost.lambda and Boost.Phoenix

http://sourceforge.net/projects/fcpp/

http://www.boost.org/doc/libs/1_45_0/doc/html/lambda.html

http://boost-spirit.com/dl_docs/phoenix-2/libs/spirit/phoeni...

Re: Functional Programming with Java

#20

Does anybody know if there is a library like this for C/C++?

After a quick Google, I see there are a few. So I change my question to: has anybody used and liked/disliked one of these libraries or a similar one?

The main ones I could find were FC++ and FACT:

http://www.cc.gatech.edu/~yannis/fc++/ http://hci.usask.ca/people/ragu/writings/FunctionalProgrammi...; http://www.fz-juelich.de/jsc/FACT/Old_Pages/fact_index.html http://www.boost.org/doc/libs/1_45_0/libs/functional/index.h... http://okmij.org/ftp/cpp-digest/Functional-Cpp.html or http://www.haskell.org/haskellwiki/Calling_Haskell_from_C&#6...; :)

Post reply on HN