Will there be a functional language which does for the Java community what F# does for the .NET community?

StackOverflow https://stackoverflow.com/questions/169812

  •  05-07-2019
  •  | 
  •  

Question

Will there be a functional language which does for the Java community what F# does for the .NET community?

What functional programming languages are available, or in development, for the JVM?

Was it helpful?

Solution

Perhaps Clojure. It's not statically typed, but it has more of an emphasis on immutability and concurrency than F#. However, like F# (and unlike Common Lisp), it is intended to be a primarily functional language that is good at consuming OO libraries from the underlying platform.

OTHER TIPS

Scala would be the language.

Though not strictly functional (it's a mix of functional and object-oriented) and it is not strictly for Java (there is a .NET version of Scala), that would be the closest analog to F# in the JVM.

The first thing that came to my mind was Scala but really Ocaml-Java comes closer as F# is a variant of Ocaml. See this post that compares Ocaml-Java to Scala:

OCaml programmers are typically over 10x as productive as Java or C++ programmers for a wide range of practical tasks. Despite being based upon a fundamentally OOP platform, F# goes a long way to capturing the productivity- boosting benefits of OCaml (and the whole ML family). In contrast, Scala fails to capture many of the benefits including some really basic ones and, consequently, writing correct code is much more difficult in Scala than in any real ML.

Moreover, the ML family of languages are designed to be succinct but Scala is needlessly verbose for everything from "Hello world!" upwards. The ML family of languages provide extensive type inference (OCaml more than most) but Scala has only rudimentary inference by comparison. OCaml has an unusually expressive type system but Scala adds little to OOP that is of practical importance.

For now I would say Scala. But for the future, I'd have a look at Fortress. The first implementation of the spec was released on April 1, 2008. And no, that is not a joke. Key featues are:

  • Statically typed, but a lot of type inference to avoid clutter
  • Unicode and 2d rendering of mathematical functions
  • Designed for parallel execution (for each defaults to it)
  • Strong support for custom libraries (Guy Steele's influence)
  • Operator overloading, including the juxtaposition operator

More info at the Project Fortress Community website and the Wikipedia Fortress page.

Arguably none because the JVM lacks tail calls and they are required to make almost all functional code robust with respect to stack consumption.

The nearest thing to functional language implementations on the JVM are Clojure, Scala and the OCaml-Java project. Although there are workarounds for the lack of tail calls (e.g. trampolining), none of these language implementations do this because the workarounds introduce even more serious problems, e.g. crippling performance and completely obfuscating debugging.

Sun have been talking about tail calls for years and, more recently, have indicated that they intend to implement them imminently. As soon as that is done, I am sure we will see a lot more language diversity on the JVM and, in particular, some production-quality functional language implementations. Until then, I regard all of these languages as toys.

Cheers, Jon Harrop.

There's a good list of programming languages for JVM, including functional programming paradigm and other paradigm languages on:

  • en.wikipedia.org/wiki/List_of_JVM_languages

My first pick is Scala (multi-paradigm; OO & FP), I spent a 5+ months studing Scala in 2009, and created a quick reference sheet: bchiprog.blogspot.com/2009/05/scala-cheat-sheet.html

I noticed there are other programming paradigms that are interesting, other focuses on parallel processing such as X10, Fortress, and Chapel. X10 is implemented on top of Scala - http://www.scala-lang.org/sites/default/files/odersky/scalaliftoff2009.pdf

It's really based on what problem you need to solve then pick the language that can best solve it. I think it's developers' wish that there's one language that can solve any type of problem easily and doing it simply.

@Marc Gravell - functional languages are increasingly used in the guts of enterprise grade financial systems. We use many functional (pure or "semi-pure") at the bank I work for...

Meanwhile, there is Frege, a pure functional, non-strict language in the spirit of Haskell that compiles to Java, which then is compiled further with javac or the eclipse compiler, depending on the environment (command-line or eclipse).

Actually, I might be wrong, but I don't expect F# to be as mainstream as the other .NET languages; useful in a few circles (academic, compilers, a few other scenarios) - however, don't forget that C# offers FP usage - and it gets better each time: C# 1.2 has delegates; C# 2.0 has anonymous methods and captures/closures; C# 3.0 has lambdas for simplicity, and Expression for abstraction. Anonymous types (C# 3.0) share some similarity with tuples (in terms of convenience), but obviously are very different beasts, so definitely not a like-for-like comparison.

Maybe not quite as optimised as F#, but for most day-to-day FP use-cases, more than sufficient.

It is also quite clear that better support for immutability (especially for threading) is very much on the minds of the C# language team for future consideration.

My money is on C# getting better at FP, and being the .NET FP offering for most day-to-day purposes. Of course, there will be some F# usage - but (purely subjective) I simply don't see there being a huge migration.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top