Haskell is a statically typed language- famous for cussing Ocaml’s lack of purity- whose entire presence on Tiobe index consists of people asking “Why should I learn Haskell?” on stackoverflow. Haskell defining feature is monads its type system (however, make no mistake: there are more advanced ones, but Haskell got more web scale frameworks than all of those combined). The nice thing about good type systems is that they force you to see everything in term of types. This statement might seem tautological, but once you get rid of weak Java-like static typing and can spot even the type of types- ahem, kinds- things start to make sense in a sort of organized, Category Theory way, so that you can ditch superfluous things like documentation, as you have all types nicely displayed above the definition of stuff. But what does such type system have that makes it so good and advanced?, may ask you. As always, let’s build leg strength starting up from easy steps:
- Existentially quantified types
In Haskell, even the most innocent looking functions hold key features. Consider the identity function, defined as:
Its type, however, reads:
Yay, polymorphic types for free, without silly angles! Oh, wait, those are universal types. Can we tone down the ⊥s?
See? With state-of-art types we can crudely construct the heterogeneous lists present in every single dynamic language out-of-the-box. So forth, if we turn on the nice extension RankNTypes,
we also can have variables like virtually every existing language! Take that, LISP macros!
- Clarity
Another thing we might say to Haskell’s favor is its no nonsense philosophy. Who never walked down the street and thought “Man, a fixed pointer combinator is all I need”!?
While other languages, such as C++ or Python, use fancy (and overrated) constructs like assignment or while loops, Haskell features only intuitive, down-to-earth practicalities, e.g., free monads, yoneda lemmes, type level recursion and, of course, several clear ways to do streaming IO. I wish they had showed me recursion schemes with catamorphisms when I first learned how to program.
- Type families
Type families solves those problems you otherwise wouldn’t have with simpler languages. The recommend approach is to use them together with type level literals. Let’s see an example:
Move over simple dynamic dispatch (you, SmallTalk) or no mental overhead dynamic typing- we can play type level Pokemon.
Summing up, Haskell is de facto practical man’s language. While its use is best advised where cheap PHP hosting is currently employed, its advanced type system can help you leverage all kinds of abstract nonsense.