š¹Ā Hate reading articles? Check out the complementary video, which covers the same content.
If you have ever wondered which functional programming language is better than others, which one to pick, or which to learn ā here is my subjective tier list.
ā ļøĀ Note that Iām a bit biased towards statically typed languages.
š”Ā If you havenāt seen one of these, we go from D (bad/terrible) to S (the best/excellent).
Haskell
Letās start with Haskell. If you can only take one functional language to the desert island, you should take Haskell because it offers so much. Sure, itās not for everyone ā it has a steep learning curve and can feel like throwing someone into the water to teach them how to swim ā but it can be well worth it.
Laziness ā a major reason to use Haskell, also a major source of frustration. Also, Haskell provides great concurrency mechanisms and powerful type-level machinery with great type inference. All of this has been there and stable for more than 20 years. Nevertheless, Haskell keeps growing ā there is always more stuff to learn and experiment with.
Seems fair that Haskell is an S-tier fp language.
Scala
Scala, on the other hand, offers a gentler learning curve and you can dial up the functional programming at your own pace. You canāt go as āfarā as Haskell, but you can go pretty far.
I have a special place for Scala in my heart.
I think Scala is an ideal fp language for Java developers and has an excellent free course for functional programming beginners.
Without doing any research, Iām pretty sure Scala is the most used fp language in production.
Scala also deserves an S-tier.
OCaml
OCaml is another language that offers OOP/FP flexibility. OCaml 5 was a strong release, which not only brought multicore but also a lot of attention to the language.
When people talk about OCaml, they often talk about a powerful module system, performance, and strong developer productivity (e.g., reversible debugger) ā but I canāt speak on that because I havenāt used it in proper projects. I can talk about my favorite features: polymorphic variants and effect handlers. Polymorphic variants is my current preferred way of dealing with errors, and Effect handlers seem to me like a future of the control flow. Two features I wish every language had (or will have).
Overall, I donāt have much experience with OCaml, but S-tier
feels fair.
PureScript
Going back to a language I used: PureScript. I think itās highly underrated.
How do I put it? Itās like a tidier version of Haskell ā in my opinion, itās easier to learn and get into.
It has a solid interop with the JavaScript world ā so, you can slowly introduce it to your project and at the same time have access to the sea of js libraries.
On top of that, PureScript offers great records and row polymorphism. I know I keep bringing this up every time, but any time I have to manipulate some data, especially json, I miss not using PureScript.
Unquestionably S-tier.
Elm
Elm is a sibling of PureScript, and itās even more focused. Itās both focused in the āfeaturesā it provides and focused on beginner friendliness. I bring this up in my video on values: itās not for everyone but has a solid niche.
Elm is another great way to tap into fp from the frontend direction.
Because it has clear values and focus, itās a solid S-tier.
Roc
If I understand it correctly, Roc is bringing Elmās values and mindset to the backend. Or at least extending on those.
It has an attractive approach to balancing (or navigating) between prototyping and reliability ā they promise a nice flexibility of dynamically-typed languages with a seamless switch to the other mode, where you actually handle both happy and error paths.
š”Ā I donāt have time to get into this, but if this sounds vague but exciting, Iād recommend looking into it (either watch a full talk on this or actually try it yourself)
On top of that, I think their anonymous sum types look fun (together with all the open and closed records and unions). And Iām also curious where their ideas around different platforms are going to lead.
Roc doesnāt have a āstableā release yet, but I say itās an upcoming S-tier.
Unison
Unison is another new kid in town. And I think Unison can compete with Haskell on an amount of mind-breaking concepts. I donāt even know where to begin. Two of my favorite things:
1) Everything is a function: deployment is done with a function call, calling another service is a function call, and accessing storage is a function call.
2) Abilities ā Unisonās implementation of direct-style algebraic effects, similar to OCamlās effect handlers.
safeDiv3 : '{IO, Exception, Store Text} Nat
safeDiv3 =
do
use Nat / == toText
use Text ++
a = !randomNat
b = !randomNat
Store.put (toText a ++ "/" ++ toText b)
if b == 0 then Exception.raise (Generic.failure "Oops. Zero" b)
else a / b
Did I mention that they promise to eliminate yaml? S-tier.
Gleam
Gleam had a v1 release a couple of months ago. Itās a friendly language on top of Erlang runtime. Itās a simple selling pitch, but quite a strong one.
And they have the sweetest mascot. What other reasons do you need? S-tier.
F-sharp
Once again speaking of interop, F# might be an obvious fp choice for those on the .NET: either youāre using C# already or want to make games using popular engines.
And I keep seeing people bringing up F# for Fun and Profit ā it looks really fun.
I havenāt touched F# ā Iām a bit biased. So, S-tier.
Takeaway
As you might have guessed Iām pretty excited about functional programming. There are a lot of options, targeting different platforms, audiences, and values. Just pick your poison.
Top comments (2)
What are the characteristics of a functional language? It's an honest question. It seems to me these days that the line separating FP from OOP languages is blurred. I mean, I never thought of Scala being an FP language, but I don't know the language well enough, it looks very OOP to me. But I've seen people mentioning Scala, Rust and Swift as functional languages as well. I don't know anymore. :D
Ask 10 people what functional programming is and get 7 different answers.
After that ask if pure functional programming is different and make it even worse.
There is no one functional programming and there is no good definition of either term.
I useĀ functional programmingĀ (andĀ fp) as an umbrella term for the assortment of concepts and values. I also share my thoughts on core ideas found across the primary fp schools of thought, even if they get different emphases and come in various forms (some are more universal, while others are more prominent in specific communities).
Imagine FP is like whiskey. Of course, there is a significant difference between an archetypical Isles whiskey and an archetypical Irish whiskey. Of course, some people got mad at the āwhiskeyā spelling instead of āwhiskyā. The point is, that some essentials make whisk(e)y different from beer. And this is what it's all about.