Retrospective on learning Haskell

It’s been something like 6 months that I started using Haskell for real and I think I’ve got past the point where I can say that I’m comfortable with it ; it’s usually the good time to take a halt and look back and identify the things that weren’t as smooth as one could have hoped.

The good part

At its core Haskell is an amazingly simple language: after you know how to define and call functions and how to define new types and type classes, there aren’t a lot of feature left to understand. I made a small presentation in my company saying that you can learn Haskell syntax in 10 minutes, it actually took 20. That’s still way below the time it takes to learn all the oddities of a language like C++.

The IDE support is quite good. Yes I know there are all kind of memes around this fact on Internet, yet there’s now a Langage Server Protocol for it which is very decent. It still struggles for big projects, for some reason it doesn’t work if there is a compilation failure when I start VS Code and may lack some refactoring tool (like renaming symbols) but other than that I can’t complain: it’s able to show the type of each variable and function in the code, and even with documentation when available, and jumping to definition just works. It also shows unused imports and language imports, something I wish was available for more mature language like C++.

Writing in Haskell helps practice Category Theory concept. Category Theory defines a lot of concepts which I often met with a « so what ? » mood at first read, but their relevance becomes so much more obvious when using them. For fun I ported a 300 lines code that parsed a specific CSV file from Python, and I ended up with something like 15 occurrences of a functor and 11 occurrences of a monad. I have yet to see how some other concepts like Adjunction translate in Haskell and read all the paper about the Categorical Language Query language which uses fibration.

The bad part

Haskell libraries are real beasts. Most of them have very useful features but it always feels like I’m learning a whole new subject each time I just want to use something. The lens libraries are really satisfying to use but there are tons of operators to discover. When reading about parsing in Haskell (one of it’s strengths) I encountered lot of daunting terms like Alternative functor and monadPlus, the former apparently being « just a monoid in a (non canonical) monoidal category »… It’s always challenging.

I can’t mention having 2 build tools is confusing a lot when beginning. As far as I understand Cabal is handling dependencies and Stack is handling the versioning of these dependencies, but apparently Cabal seem to have gained some functionalities lately in this department.

I discovered the hard way that the base library is unsafe which is non-diegetic for a langage that focus so much on safety. The (!!) function for instance doesn’t return a Maybe but an object, and if it fails it crashes. The solution is to use another base library (called relude) in the Stack/Cabal dependencies. It’s something that’s not emphasized enough in my opinion (I discovered it while browsing Zulip funprog channel).

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *