r/functionalprogramming • u/lovelacedeconstruct • Feb 11 '25
Question What is the "Java" equivalent in FP Languages ?
I dont write java anymore but my experience with Java back in college was that it was very good introduction to OOP, everything was a class, syntax was very close to the diagrams, it felt like the concepts of OOP was just all there and you are forced to think using them, not saying whether thats a good thing or not or whether my assessment was correct but what do you think is the equivalent for FP ?
36
Upvotes
56
u/_abysswalker Feb 11 '25
has to be haskell. in fact, any pure language forces you to think in functional terms, you don’t really have a choice otherwise
55
u/lpil Feb 11 '25
OCaml is often used in educational contexts to teach FP, the same as Java is often used to teach OOP.
34
u/ibcoleman Feb 11 '25
Others have said Haskell, but the other “flavor” of FP is a Lisp like Clojure.
10
u/a3th3rus Feb 12 '25
Elixir is pretty easy to learn, pure enough, and fairly pragmatic.
If you want to learn an extremely pure FP language, then it has to be Haskell.
9
u/TheBlueWalker Feb 11 '25
Haskell is purely functional, and has a mature ecosystem with many libraries compared to other functional languages much like Java compared to other Object Oriented languages. Haskell also has a good type system, so it is like an implemented type theory. Haskell is good for learning FP.
Otherwise, if you are more into lisp-like languages instead of ML-like, Scheme would be nice for learning FP, too. It is very simple and there is a good book that uses it to teach computer programming in general called "Structure and Interpretation of Computer Programs". Scheme is not purely functional, but it does encourage functional programming. Scheme has no types, so it is more like the untyped lambda calculus.
I think Haskell may be better because it is purely functional. But Java is not purely OO so if you liked Java for learning OO you might Scheme as well. Scheme is simpler and allows you to focus on computer programming in general while Haskell forces you to learn about all kinds of features used to preserve functional purity, like IO Monads. I suppose the latter is a good thing if you really want to learn about FP.
7
u/andrewcooke Feb 11 '25 edited Feb 11 '25
there's nothing obvious because fp isn't as popular and java implies popular. but from your description i'd say haskell or scheme (lazy and statically typed, or eager and dynamic).
12
u/GunpowderGuy Feb 11 '25
Racket for sure
4
u/tesilab Feb 12 '25
OCaml is a practical productive choice with one primary caveat - it provides just enough mutable constructs to act as a crutch preventing you from truly learning FP.
Haskell is a fantastic choice for learning, and you'll get FP constructs in spades, and beautiful infinite types brought to you by being lazy as well as pure, together with some heavy duty typing.
Either way, once you've got it down, you are also ready to take maximal advantage of all the FP inspired constructs that have made it into mainstream languages.
2
u/QuirkyImage Feb 11 '25 edited Feb 11 '25
Scheme can be used as a multi paradigm language to introduce first year to both imperative and functional. Racket has been used well for this. I would say Haskell would be the end goal
2
u/hasparus Feb 12 '25
Definitely Haskell. I think it was either second or fourth semester in my uni. Though I've heard they're doing Racket now.
2
u/ExoticWin432 Feb 12 '25
Scala is the Java FP version, but I wouldn’t recommend it for learning FP since it’s a mix of OOP and FP. it’s better to use a pure FP language like Haskell.
2
u/GrowlingOcelot_4516 Feb 14 '25
I learned with R, though they have added aspects of OOP in the more recent years.
2
u/Apprehensive_Pea_725 Feb 15 '25
For pure functional programming is Haskell, everything is a pure value and no side effects except in very specific and delimited parts.
Pure FP can be adopted in other ways in other languages but it requires more discipline.
For non pure FP, Erlang, F#, Ocaml, Scala, not everything is a pure value and side effects are not constrained in general.
2
u/baldram Feb 13 '25
Scala. It stands out as the industrial-strength Java equivalent in the FP world, offering a perfect blend of functional purity and practical power while leveraging the entire Java ecosystem.
1
u/tbltusr Feb 11 '25
OPAL
1
u/TheRealStepBot Feb 11 '25
Ironically Java itself has fairly decent support for many functional ideas.
1
u/xiaodaireddit Feb 11 '25
Common lisp
-9
u/DataPastor Feb 11 '25
If you mean kitchen sink, overengineered languages, which prefer feature fullness to simplicity, then it is Scala, Haskell and recently Rust.
0
u/[deleted] Feb 11 '25
[deleted] — view deleted comment