r/functionalprogramming • • Oct 20 '23
Question Practical FP language: Ocaml vs Erlang
Hey everyone, I am learning Java at school right now, and I am planning to learn C++ because of its versatility, I have tried Ocaml but nothing serious, and I wasn't used to the syntax but I want to get serious with the FP concepts.
At school, there is an opportunity to research another language, I would love to learn an FP language that is fast, practical, battle-tested, and general-purpose which I can use for web servers and data processing, network programming, or some system programming.
I am not considering JVM ones, and although I know Haskell is great I would prefer something for industrial, I have experience programming JS/TS in FP style here and there.
Which one should I pick? it could be something other than Ocaml and Erlang!
Thank you very much!
Let's go with Haskell!
Going with Haskell feels like learning C, it will be hard but the foundation is everything. Although Scala will have more jobs and Elixir is fault-tolerant I hope once I get the fundamentals of functional programming, learning another fp language should be easier!
Thank you again for everyone's thoughts let's see the languages suggested by you guys!
Updated the count, but I won't be updating the count onward I've linked to the langs' official site just in case anyone wants to check them out in the future
let me know if I miss any, tough pick but thanks again, everyone!
16
u/zestsystem Oct 20 '23
Haskell is a great general purpose language. Haskell has more industry adoption than Ocaml despite the memes. Since the main goal is to learn FP in college why not learn haskell?
11
u/yawaramin Oct 20 '23
For 'systems-y' programming, you probably want to go with OCaml, it has a very C-like runtime model but with a static typechecked functional programming style compiler for those great safety benefits. Check out the Unix programming in OCaml book by the creator of the language: https://ocaml.github.io/ocamlunix/
For web programming and data processing, Elixir has some pretty good offerings: the Phoenix web framework is mature and performant, the Broadway library is specially developed for data processing, and Nx and Livebook are the offerings for data science. For those and many other use cases, you basically can't go wrong with Elixir.
9
u/linlin110 Oct 21 '23
For learning purpose Haskell is certainly a great fit. You cannot use techniques you learned from other languages and will be forced to learn pure functional programming. You can then switch to a more popular language and apply what you learned from Haskell. This is the most effective way to learn a new programming paradigm IMO.
14
u/Rogntudjuuuu Oct 20 '23
I'd suggest Elixir instead of Erlang. It runs on top of the same VM. Also, consider Elm for front-end, it's very close to Haskell. Another contender could be F#. It runs on top of dotnet and can also transpile to Javascript. F# is based on OCaml.
5
u/plum4 Oct 20 '23
100% use Elixir (over Erlang) rather than OCaml for the cases you listed. The primitives for doing distributed/web computing are unparalleled. It will be difficult to do system programming with it though.
13
u/Il_totore Oct 20 '23
Why don't you consider JVM functional programming languages like Scala or Clojure? The former looks like a good choice to me considering your Java background and its industrial adoption.
4
u/GunpowderGuy Oct 20 '23
I am learning idris2 since it's got a way more powerful type system than haskell and lacks it's technical debt. I think the package manager Is easier to use too, although i haven't tried to install haskell in a while
4
u/frej Oct 20 '23
Since you want to learn right now, I would suggest a language with a solid thought-through type system (Ie, OCaml, Haskell, etc.). Don't waste time on C++/Typescript for types. It is either just there for performance or bolted on with plenty of warts.
Ocaml has excellent university-level material for students to learn to program in any language, in this case with OCaml. It has also proven its worth in a few industrial settings.
https://cs3110.github.io/textbook/cover.html
Erlang is an excellent good choice, also to understand. It is mostly due to its runtime and lessons on building reliable systems and software.
4
u/reformed_goon Oct 21 '23
Elixir if you want to actually have something in production at the end of the day.
4
u/chehsunliu Oct 21 '23
For industrial I would definitely choose Scala, JVM-based (plenty of libraries) and heavily used in data engineering (Spark). However it’s multi-paradigm, which you could still write code in the imperative style.
For the FP learning, I would recommend Haskell and Elixir.
4
u/witoldsz Oct 24 '23
I would definitely vote for F# not just because I use it daily, but because it has a nice feature set for BLOBAs, i.e. boring, line of business applications – which is like 99% of all software written.
https://fsharpforfunandprofit.com is a superb repository of knowledge you can use not only in F#.
The one downside of F# is that you can have hard time if you are not super familiar with dotnet/C#. Most of the books and articles are guided at dotnet/C# devs, which was somewhat problematic to me, because I've started F# with no prior dotnet/C#/MS-whatever background (including Windows, which is today not required to use F# comfortably).
On the other hand, I would vote against Scala. I will probably get down-voted heavily for this, but in my opinion Scala is terribly designed. It is a very complicated language and this is something you won't see immediately. It is sad for me to watch that not only OOP are a mess, but some FP, like Scala, can be a mess too.
7
u/mesonofgib Oct 20 '23
Strong vote here for F#. It's a functional-first but mixed-paradigm language, and benefits from the enormous ecosystem of libraries and frameworks available on dotnet. Editor support is also much better than other languages in this class.
6
u/Voxelman Oct 20 '23
Before you learn C++ you should consider learning Rust.
3
u/miyakohouou Oct 20 '23
I'll echo what some other folks here have said and suggest Haskell. Haskell is definitely used in industry, and it's probably going to give you the biggest learning opportunity of the things you've listed. There are a ton of great resources for learning Haskell, libraries for all of the things you are interested in, the tooling is getting a lot better (and some of the tooling, like
hoogleis best-in-class), and it has great performance.3
u/v4racing Oct 21 '23
Elixir is way more pleasant to write than erlang but both are cool languages. Ocaml would be more general purpose though.
3
u/sharno Oct 21 '23 edited Oct 21 '23
I think you have to consider what you will learn with FP in the language.
Elixir will teach you about how the OTP works and concepts related to that but it doesn’t have types, so you’ll get more runtime errors.
Haskell will teach you about laziness and more advanced type system stuff. It’s really the most powerful type system of all that’s suggested.
OCaml will teach you how to mix FP with mutability. It’s more practical in general than Haskell but with a very close type system in terms of strength to Haskell. It also has a new concept of Effects which was added later.
I suggest to take a look at Unison. It’s more like Haskell but very new and has some nice ideas for code immutability.
F# is like OCaml but you get to know more about the dotnet ecosystem because you generally need to use libraries from C#
Clojure and Scala will teach you about Java and the JVM. Clojure is untyped. Scala is typed. Scala libraries are mostly based on Haskell so you might learn some about Haskell along with Scala.
Elm is like a very simple Haskell that works in the browser. You’ll learn about JS and frontend development.
Rust will teach you about low level stuff like memory management and new ideas of borrowing and ownership. Your code will look generally uglier than the past suggestions but runs much faster. And it’s the biggest job market out of all of those.
3
u/mkunikow Oct 21 '23 edited Oct 21 '23
Very good article about Haskell.https://www.snoyman.com/blog/2019/11/boring-haskell-manifesto/
https://gist.github.com/srid/ea35390ef99ad14aa710ca5a85aad3c2
Should you learn haskell for first FP language to learn FP - Yes.Should you use it on production -> check article.
Also interesting check this guy bloghttps://www.snoyman.com/
3
u/[deleted] Oct 21 '23
Haskell won this competition. If someone is okay to use a little-used language then i certainly recommend Haskell, no competition.
Though you mentioned "systems programming". I would be skeptical about Haskell for low level job. For that you may want to consider Rust, beside C++.
3
u/[deleted] Oct 21 '23 edited Oct 22 '23
What does Rust in this list. You can't call it practical if you can’t pass functions around without doing Box<dyn Fn left and right.
4
u/gusdavis84 Oct 20 '23
What's wrong with clojure? You mentioned you wanted something that was practical, battle tested, etc. IMHO that's clojure hands down.
3
u/imihnevich Oct 20 '23
Haskell is quite good for web servers
3
u/0xAERG Oct 20 '23
I love Clojure. But OCaml is my favorite language of all. I’m in love with its syntax
Clojure lacks of a type system.
OCaml has one of the best compiler and type inference, if not the best of all.
2
u/[deleted] Oct 20 '23
Scala could be a good option and Rock the JVM has really good video courses on it https://rockthejvm.com/ and functional focus. Scala is the Haskell of the JVM. Im learning about functional programming and I'm getting in to the deep end and I really like both Haskell and Scala and they seem to be the only two bigger languages with real support for Higher Kinded Types which is a useful concept for FP even though it can be emulated in lesser functional languages.
4
u/SIRHAMY Oct 21 '23
This is an older post, but my 2 cents base on languages that seem to be chosen semi-regularly for standard app builds:
The others are good languages in their own right but these are the ones that seem to have higher retention rates / practicality among people starting out with FP or continuing to use in general application development.
7
u/[deleted] Oct 20 '23
[removed] — view removed comment
1
u/[deleted] Oct 20 '23
[removed] — view removed comment