Coffee, Curries, and Monads — My journey through Haskell

A Time to Reflect

I sat in a coffee shop reflecting on my journey in Haskell today. It was spurred on by briefly seeing the whole “monads are pipes” thing and some responses to it. I don’t involve myself in these discussions generally, and I’m not going to here. What I am going to do is tell you a little about myself, my programming journey, and why I enjoy programming in Haskell. Hopefully it will encourage you to try it out and witness your own joy with the language.

First Encounters of the Haskell Kind

Sat upstairs in a lecture room in Trinity I heard the name Haskell for the first time. “A pure functional and lazy language.”, stated my lecturer. “Sounds like my kind of language”, I jested. My friend Ian scorned me, saying that it meant lazy in the evaluation sense and not what I was thinking. I made fun at the time, but little did I know that it really would become “my kind of language.”

There was an uphill struggle as I tried to grasp the new, wonderful and strange features of the language. Immutability, pattern matching, abstract data types, typeclasses and much more were very foreign to me. Even the dreaded Monad was encountered and it did not sink in at the time.

Cup full of Beans

The thing is, I had this exact experience twice before during my computer science degree. The first occurred when I was first learning programming through Java. I was immediately lost with loops, if/then/else and objects. Our lecturer threw us in the deep and end and many of us thrashed against the waters. Only thanks to the second semester lecturer, Arthur Hughes, I was able to understand programming better. There was an emphasis on breaking down problems into smaller parts and building up the solution.

I cannot C what’s happening

The second incident of programmatic drowning was encountering C for the the first time. With some assembly under my belt I was familiar with what was going on at the lower levels of programming. But when I had to start thinking about pointers and memory in this language, I quickly became lost. Segfaults became the bane of my life as I tried to trace where the issue was occurring using the tried and tested technique of printf . With enough practice I became more and more comfortable with the concepts and I was eventually able to program C at a competent level. Well, enough to obtain a good grade. I would not program C professionally today — not without a month or two of studying the language again.

Practice makes Perfect

The running theme of these two incidents was that there was a struggle in learning at the beginning. I persevered by practicing over and over, ingraining the concepts into my head, and finally, understanding what everything was all about. Learning does not come for free. The cost comes in the form of your precious time as you work to achieve the results you want or expect. Haskell was no different for me.

My story in Haskell continues when I took on the follow-up module of functional programming the next year of college. We went through more functional techniques and concepts: Generalised Abstract Data Types, concurrency primitives and Monad Transformers. These concepts still felt a bit out of grasp, but I knew there was something there. There was something that kept pulling me back to Haskell. I finished the module and Haskell became more of a reading hobby over the next couple of years.

Master of None

My enlightenment came while I was procrastinating my Masters thesis. I loathed the topic I chose so much that I reached for anything else that I could do to take me away from it. Couple that with my tendency to productively procrastinate, Haskell Programming From First Principles, by Chris Allen and Julie Moronuki, was the perfect escape. Starting from the basic building blocks, I went through exercise by exercise; chapter by chapter. As if picking a body part and exercising it over and over, my Haskell muscles became stronger and quicker. Repetition ensured that I had a reflexive memory of what I was learning. Everything finally began to click into place and I began to understand what the hidden feeling was. I understood why I liked Haskell so much.

I see Haskell as a language that works with me as much I work with it. The structure of programs via expressions and immutability help me think about what I’m trying to achieve with the program. In a way, I always felt like I’m trying to trick programs into working for me when I wrote Python. It’s the opposite for Haskell, I’m just putting a bunch of puzzle pieces together and nothing more needs to go in. I look at the pieces and match them up; simple. If I change the pieces it’s immediately apparent how to change the rest, refactoring really is a breeze. This is the first thing that comes to mind when I think about writing Haskell, but there is so much more. I’m far from done learning the great techniques and concepts in Haskell and functional programming in general and I’m glad for it. To keep learning is a key philosophy of mine.

Pay it Forward

I took my new found knowledge and began to look at writing Haskell more seriously. I contributed to open source projects, with the helpful push from Chris Allen, who I can now call a friend :). I grew so comfortable with the language that I gained enough courage and applied to Formation. I was able to get the job and have been writing Haskell professionally for more than half a year now. As well as this, one of my favourite things to do in my free time these days is to help people learning Haskell by answering questions on Slack and co-organising a study group in Dublin.

I have been approached on multiple occasions by hopeful programmers wishing to get a job writing Haskell. I generally give them a shorter version of this story. This is why I’m writing this today, to encourage those people and just about anyone who is willing to learn Haskell. Encourage them to not be afraid or scoff at things that seem technical. Encourage them to try a programming that will challenge them just like they felt challenged with their first language. I found joy in programming Haskell and I hope you can too!

Edit: I missed credit to Julie Moronuki who also authored Haskell Programming From First Principles. Apologies Julie, and thank you Kris Nuttycombe for pointing that out!