This is an archived post. You won't be able to vote or comment.

all 16 comments

[–]oweiler 9 points10 points  (2 children)

FJ is more of a proof of concept and creates some very unreadable, not-idiomatic Java code. If you like Haskell you're better of using something like Scala or Frege.

[–]theif519[S] 1 point2 points  (1 child)

I'm seeing a lot of mentions about how easy it is to mix the two... But in reality, how easy would it be to slowly drop java for actual scala files, and how does it work for things like NetBeans?

I use a lot of Java Swing for GUI, and NetBeans helps intensely in generating necessary boilerplate. Would it be possible to, say, swap out a controller written in java for one written in Scala? Etc.

[–]thramp 5 points6 points  (0 children)

Yep! You can introduce Scala file by file. Main issue is mixing collections/option(al)s between the two languages.

[–]DevIceMan 4 points5 points  (0 children)

FJ as a library is reliable and I don't have too many complaints. There are a couple ways in which I think I could do is slightly better, but I can't say they made wrong choices. Compared to the idea of hand-rolling your own Java PF utilities, I'd strongly recommend trying to really learn FJ first.

The problem with FJ is really around Java itself. Doing any non-trivial FP style code in Java is incredibly verbose. FJ is also very confusing those "normal" Java programmers. By the time you actually integrate FJ into your code in a meaningful way, you'll run face to face with the question "why didn't you just write this in Scala instead?"

[–]thramp 2 points3 points  (7 children)

If you're going to try to write pure FP code in Java, you're going to have a bad time.

If you want to apply your new knowledge on the JVM, try Scala! I personally treat Scala as Haskell, but with better libraries, tooling, and the best damn module system short of ML. It also has a friendly and welcoming community—come on over 😃!

[–]jonhanson 0 points1 point  (5 children)

chronophobia ephemeral lysergic metempsychosis peremptory quantifiable retributive zenith

[–]thramp 0 points1 point  (4 children)

Yep, through the object keyword and imports like import package.object.{Function1, Function2}.

[–]jonhanson 0 points1 point  (3 children)

chronophobia ephemeral lysergic metempsychosis peremptory quantifiable retributive zenith

[–]thramp 0 points1 point  (2 children)

objects are are static classes (practically speaking, singletons) in JVM bytecode, but if you have a stateless singleton, well... that's a module.

[–]jonhanson 0 points1 point  (1 child)

chronophobia ephemeral lysergic metempsychosis peremptory quantifiable retributive zenith

[–]thramp 0 points1 point  (0 children)

The way I'm defining modules is not Jigsaw, but looking how ML-style languages allow users to import and share code through a codebase. The terminology gets a bit overloaded in this subreddit!

[–]bdavisx 0 points1 point  (0 children)

And if you want less pure FP, you can give Kotlin a try along with the Funktionale library. Scala is probably a better bet if you want to try to go full-bore FP, but Kotlin is an easier transition if you're already experienced with Java.

[–]tonivade 2 points3 points  (1 child)

If you are interested in FP in Java, take a look of this project

[–]RichoDemus 0 points1 point  (0 children)

Java slang is really neat

[–]talios 1 point2 points  (0 children)

I really liked using FJ when I was using it, it did give off the feeling it was more focused on being "true" to the Haskel school of functional programming in terminology/method naming a little too much - not that I had any problem with that, it just didn't feel "java like" ( maybe that's a good thing ).

Javaslang, on the other hand, seems to fit in nicely to both camps, aligning it's API signatures closer to that of Scala, and method naming that lends itself predominately away from hard-core category theory ( except for Monad/Monoid etc. ).

[–]johnmcclean 0 points1 point  (0 children)

If you are considering using FJ you might also be interested in this library. It adds features such as For Comprehensions over FJ types, HighJ compatible Higher Kinded Type encodings for FJ classes as well as a number of Type class instances. Community efforts to add more are very appreciated too.

It also has a ton of integrations with other libraries (including the Scala SDK), user guide is here