A week of Haskell

2019-04-05

The premise

So we had a HackWeek at XING, and I chose learning Haskell as my project this time. Around the same time last year, I built a small savegame editor for Starbound in Haskell. I didn't really grasp what the language is all about, and ran into trouble constantly.

I still wanted to know the language better, but in between doing $WORK, Nix stuff, keeping up with the usual JS and Ruby insanity and relearning Elixir & Phoenix, there wasn't much time for it.

For this time, I chose the Learn You a Haskell for Great Good! book. Mostly because it's free and in HTML, so easy to download and search.

Some nice quotes about it from #learn-haskell are:

qu1j0t3: also LYAH is just kind of ick
Peter_Storm_: Yeah, haskellbook is about a million times better than LYAH
lunabo: I liked some parts of LYAH but it doesn't prepare you very well for writing more realistic Haskell code

At the point when I read those remarks, my week was almost over, so I didn't end up buying the recommended Haskell Programming from first principles. Although in retrospect I wish I had.

The good

Well, with that out of the way, let's get to Haskell itself. It's a good language for problems that you can model in your mind beforehand. At least that's my experience. Once you got a mental model of how the data should flow, you can basically just write that down and reasonably expect it to work.

I really enjoy this aspect also in other languages, and with more practice, maybe I'll try using it for some of my otherwise hacky scripts that I usually write in Ruby or Go. Using runhaskell isn't bad, but you have to take care of dependencies a lot. The stdlib may look large, but a lot of it is simply related to what is needed to build GHC.

It doesn't have an HTTP client/server, JSON or YAML parser, and various other things I'd like to have handy when writing some simple plumbing script. In this regard it's similar to Erlang/Elixir, which just focus on the core language platform, that everything is built on, and less on the developer experience out of the box.

I can get behind this, but once you get to dependency handling it's not a simple script anymore. That's where nix-shell can help a lot.

The ugly

The LYaH tries to be funny and technical at the same time, and seems to fail at both. I got distracted by typos and some sections are simply a list of functions with a short description of what it does. There are very few exercises until you finally work on a Todo list around chapter 9. I made it to printing Hello, World! on Thursday.

The first two days were mostly spent trying to understand the relationship between Stack and Nix and how to properly setup my editor with Haskell, and there are various half-completed ways to do that.

I never found the ideal setup before giving up on that, and just went with a more-or-less working setup of the Haskell IDE Engine.

For some reason the code formatting is still broken sometimes, auto-completion is hit-or-miss, automatically inserting type signatures is still broken, it tries to add dependencies via cabal instead of stack, and I didn't spend more time on trying to get it to work with direnv or nix-sandbox, so I just used a user-global Haskell and HIE installation for Emacs.