Haskell is known as a hard programming language. For many people, the difficulty comes not from the language syntax and type system, but from the language culture and the Haskell libraries. The question is: “Is Haskell actually really hard to learn and then use?”.
One could write an entire book about all the difficulties one encounters while learning Haskell. But for most readers, this is unnecessary. As a language student, you learn how to do almost everything in almost every programming language that you use. But learning the Haskell language and its associated libraries is a different experience, even if you know C, C++, Python, or Java already.
What is Haskell?
Haskell is a purely functional programming language with type-inference, typeclasses, algebraic datatypes and more. In addition, it is highly extensible, with several libraries for parsing, manipulating, and evaluating input formats. Haskell comes with several useful tools for writing interactive applications, including the text based interpreter GHCi. A more complete list of libraries can be found on the Haskell Hackage package database.
What makes Haskell special is not so much that you have to think differently about the language or how to use the standard libraries. Haskell has a great standard library. Almost all of it is in the Prelude, and not in a library. Almost everything you want to do is documented. In many cases, your program will work without a single line of code in your own project. But you still have to think differently. You have to learn the design principles of Haskell, even if they are just a tiny fraction of the language.
Why Learn Haskell?
Haskell’s unique design puts the emphasis on simplicity. In this respect, it is the opposite of imperative and object-oriented languages. Haskell forces you to think in terms of values and types and makes it impossible to do certain kinds of mistakes. Furthermore, this simplicity makes it suitable for teaching functional programming concepts to those who are coming from more traditional imperative languages, such as C and Java.
If you are already familiar with an imperative language, you are much more likely to learn Haskell with less effort than if you are just starting out. The Prelude libraries are much more mature than those in a typical imperative language. And thanks to its great standard library, which is very complete for the type of problem you are trying to solve, you should get up and running quickly.
Also, for those with a background in imperative and object-oriented languages, the typeclass mechanisms of Haskell can make functional programming feel a lot more like a traditional imperative language. This makes learning Haskell easier.
But Haskell’s emphasis on simplicity is not just about technical issues. In order to get the most out of the language, you have to learn the philosophy of it. You have to learn the why of Haskell. This is where the community part of Haskell comes in. If you are trying to figure out what the community of Haskell is like, this is the place to start.
How to Learn Haskell
The best way to learn Haskell is to go through a real Haskell project. If you need to teach yourself Haskell, the book Learn You a Haskell for Great Good is a great place to start. Also, you can take a look on Real Word Haskell, another Haskell book. If you need a way to learn about using Haskell for practical purposes, theese books are an excellent resources.
It’s important to do some homework before you jump into a Haskell project. You should understand what it’s like to write functional programming in Haskell, and what the language is like. You should understand the benefits and the philosophy of Haskell. This is the place to start if you are just starting to learn Haskell.
Haskell pros and cons
While the language and the libraries are quite rich, the pros and cons are not as clear as they might seem at first. Here are the main pros and cons of Haskell:
Pros of Haskell
- Expressive type system: you can tell what can function do by looking on its type.
- Effective syntax: the code is more “dense” than usual, you can do more with less lines of code.
- Very flexible and versatile.
- Extensibility: there are a lot of Haskell packages and libraries.
- Lazy evaluation: the code is executed only when you need the resulting data.
Cons of Haskell
- Low demand on Haskell programmers, it is rarely used. However, popular Haskell projects exist. For example, the Cardano cryptocurrency is programmed on Haskell.
- Hard to read. As I wrote above, the code is dense, so you should focus on every line to understand it.
- Not practical. While algorithmic tasks are easily solved with Haskell, real world tasks may require more efforts than, for example, Python.
So, is Haskell really hard or easy?
Haskell is different than hard or easy. It takes a lot of time and effort to learn Haskell. But it is not as hard as it seems, even if you are coming from a programming language like C, C++, Java, or Python. By the way, some people report that Haskell is easier if you learn it as your first programming language.
While Haskell is a powerful programming language, it requires a lot of time to master it. There are a lot of learning resources online, such as books I mentioned before. Even if Haskell seems hard for you, with enough patience you can learn it easily.