Haskell will definitely stretch your brain, if you haven’t done much functional programming. It makes you question why we do imperative programming at all, after you have had a taste of lazy evaluation.
For example, consider this chunk of code that might be found in a function:
x = a + b;
y = c * d;
Since x and y don’t have dependencies upon each other, they could be executed in either order, or in parallel. And in fact, a modern compiler for a popular language will take this into account, and that plus the Out of Order instruction scheduling in the CPU will optimize execution of these statements. And in fact, depending on all the above, the computer system may just evaluate y first, x not at all, or neither if it turns out that nothing else in the code actually depends on the values of x and y.
The programmer who wrote this code still needed to think about ordering and time, even though it wasn’t really necessary. And this ordering is woven throughout the process of writing imperative code.
The Haskell programmer takes on a more mathematical / declarative approach to programming. This programmer defines that x is the sum of a and b, and lets the compiler worry about when (or if) the code to make that happen as needed. That can be very freeing in a way, because of the timelessness of the endeavor.
Not quite a free lunch though. I love Haskell (currently using it for all of my personal projects), but you pay for this type of freedom with a new class of problems altogether: space leaks, weak-head normal vs. normal forms, when to make things strict, INLINE vs. INLINEABLE, etc.
I’d still take the Haskell way over most others, but there are plenty of dark corners.
Oh, I agree, there’s no free lunch there.
I was initially entranced by that famous one-liner for Quicksort for Haskell. Of course, that code doesn’t really do what an actual in-place sort would do, and does a lot of allocations. Still, specifying an algorithm so concisely was intriguing.
I actually never got comfortable writing Haskell code, and I’ve tended to prefer imperative functional languages instead. Spending my free time with Rust these days.
Not sure why the article goes out of the way to talk about how old Haskell is, but it’s definitely older than 20 years, the first version was released in 1990, according to the wikipedia page that the article links to.
The most important reason to learn Haskell is that it’s rooted in formal logic. In my opinion, this is what we should be teaching in CS curriculums. I honestly don’t believe FP is the best way to write programs, but it’s the best way to analyze programs, because of its logical foundations.
I wrote more about this here: Quality and Paradigm: The Assembly Language of Reasoning and the Domain-Specific Language of the Machine.