Hello Haskell

Summary: I go over my first steps using the Haskell programming language and state some of the benefits I could already enjoy while tinkering with it.

I don't remember how I first stumbled on it, but I've been meaning to learn Haskell for a couple of years now. I've seen some of the videos claiming that learning Haskell will elevate your vision of programming and computing problems as a whole. And as a bachelor student, I took a Functional Programming course on Scala but somehow it did not really stick as I was too young and lacked interest back then. Plus, a colleague of mine once said that when it comes to technology, I like to use different things (you know, Linux, Emacs and the likes…) and Functional Programming definitely counts as a different thing! So all in all, I owed it to myself to give Functional Programming a (real) go, and this time with Haskell.

I started solving the assignments of the famous CIS194 course and read through a few pages of LYAH and Haskell from First Principles as a way of getting my feet wet. I later got a copy of Real World Haskell and started writing a few toy programs for fun but nothing significant. But it's only after wanting to implement a real interactive program (like some simple game you actually play in the console), that you realize that the early chapters of these resources don't cut it. Because these things in Haskell mean State Monad or IO Monad and past experience of writing Javascript and Python don't really give me a clue about all that. So I'm at this weird phase where I can't keep reading the books without actually implementing anything, and I can't write anything useful with the knowledge I have at this point.

I've had a first small breakout after I needed write a small tool a friend needed and I decided to try to write it in Haskell. It is some simple program to help him organize the weekly ~15 people schedule of the bar he is working at, as he was hitting the limit of what pen and paper allowed him to do in a reasonable amount of time. I decided to use Brick, a terminal interface library, after I saw Agentultra praising and using it for his game on stream. I could lift off pretty quickly using Brick's examples plus a bit of help from #haskell-beginners on IRC.

Once the basic data structures and the interface are figured out, it's crazy how fast it is to implement additional logic into the program. For example, I only needed to write these few lines

avail :: Widget Name -> Widget Name
avail widget
  | teatender `elem` (avail_teatenders time_slot) =
      withAttribute greenAttribute widget
  | otherwise = widget
in C.hCenter $ avail $ teatender

to have the given teatender appear in green in the list of teatenders when he is available. Just adding that teatender to the time slot's available teatenders somewhere else in the code makes everything magically renders the way I intend it to, without having to implement and bind callback functions and such. Plus, the code reads pretty naturally if you use the right idioms and variable names (which I for sure haven't). That's just one way Haskell amazes me right now, hopefully there are more down the line.

As I'm looking into having some web functionality for my program, it looks like I can't look past Monads any longer if I want to use Chris Done's Lucid HTML library. So this where the next challenges of my that journey lie. And so far, it's been already very interesting and indeed mind-bending. Exciting stuff ahead!

I know there is a lot right now that is far from being idiomatic Haskell, but here is the "Teatending" repository for reference I guess.

https://git.sr.ht/~titibandit/justbe_teatending

The content for this site is CC-BY-SA. The code for this site is MIT.