23 Jul 2019, 21:30

Learning Haskell: Session 1 - Stack

Learning Haskell

I spent the weekend learning some Haskell. My goals were:

  • learn a bit about the language in the trenches: is there any utility in learning more about this?

  • learn a bit about the toolchain: building, deploying, etc.

  • add a small plugin to xmobar, showing my age as a decimal number. Inspired by memento mori and trying to make the most of our limited time in this life.

    This is something I want to see increase slightly every day, as a constant reminder to get stuff done.

I figured the above would be a nice whirlwind tour: not enough to start monad engineering, but enough to defend myself.

Below are some notes and thoughts.

Stack

Stack is the build system I chose to use for the library and CLI. It seems a bit more modern and recommended than pure cabal, which ships with Haskell itself. Stack seems to provide a higher level wrapping around cabal to some extent, along with some other goodies like caching.

I also like Stack’s commitment to reproducible builds, creating an environment per-project with its own ghc, the Haskell compiler. I actually don’t even have ghc installed locally, so there’s no chance I’m mucking up the build by having things on my system’s PATH override any project-specific stuff.

The downside is that Stack can eat massive amounts of disk, as you’ll have a ghc for even minor versions e.g. 8.4.2 vs. 8.4.3. Something to be aware of.

Hacking on stack basically involved looking at the documentation and various YAML files, so nothing too painful, yet.

Notes

  • stack build - produce binary
  • stack run [args] - run directly from slack
  • stack ghc - if you need to shell out to ghc for whatever
  • stack ghci - start a repl

Wrap up

It was pretty painless getting set up with stack, and creating a CLI/library project.

Next up: Haskell coding, xmobar detective work, and more.