How Did You Start with Functional Programming?

Gints Dreimanis
Article by Gints Dreimanis
Wednesday, February 26th, 2020

Our engineers come from various backgrounds and fields of study. Some of them are already brilliant Haskellers when we recruit them, some of them come through internships or after showing great results at ITMO. Similarly to Haskell, Serokell is a melting pot of cultures and ideas, and we like it that way.

In order to learn about various ways one could end up doing functional programming at a company like Serokell, I asked three of our engineers how they started with FP. The answers were low-key amazing and surprisingly different from each other. While Pasquale was struck by the expressivity of the language, someone like Anton has found in Haskell a great vessel for applying his knowledge of category theory.

But I won’t give you any more spoilers – read on!

From Python to Haskell

Pasquale Pinto

I first encountered functional programming with, oddly enough, Python. At the time, it was the language I was using almost exclusively and had done so for quite some time. As such, I knew most common practices, tooling and even pointless curiosities about it, the only real exception was its (relatively uncommon) functional side.

However, after a few times I had seen/used it, it struck me as very expressive and so, out of curiosity, I decided to take a deeper look. Wandering around forums and such, eventually (perhaps inevitably) someone suggested a “real” functional language: Haskell. As soon as I opened haskell.org, I had a flashback: I had been there before, multiple times, and even completed the small interactive tutorial, but somehow it didn’t catch my attention beforehand.

This time, I decided, it was going to be different, so I picked the book that seemed the most beginner-friendly – Learn You a Haskell for Great Good and I imposed myself to finish it, hoping not to regret the time it would take. I went through the first half of it only out of stubbornness: I didn’t see what was the point and making even simple things seemed comparatively very cumbersome. Definitely not impressed.

Then all of a sudden it hit me: the first eureka moment arrived when I learned about partial application and that every function is curried. It took me half an hour just to stop considering the endless possible applications of these two combined and how composable, readable and versatile (aka elegant, I later learned) the language really was, not to mention this was just impossible in any programming language I had ever seen before.

Even though the complexity of the arguments quickly grew, and took me quite some effort to keep up, I devoured the rest of the book and kept learning from everything I could find from that moment forward.

Then all of a sudden it hit me: the first eureka moment arrived when I learned about partial application and that every function is curried.

For me, it was quite hard to implement non-toy-sized code at first, but eventually I managed to write a couple of small projects. At that point, I knew I wanted to do this full-time and lucked out when I got a position at Serokell.

I have since learned tenfold about Haskell, quite a bit about Elixir, and functional programming in general; to this day I still get surprised at the possibilities and cleverness of the community and my colleagues. So, in the end, I cannot say it has been a walk in the park, but this all makes it worth it. No ragrets.

Hanging out with teachers from Serokell

Aleksandr Pakulev

My first acquaintance with functional programming began in the first year of the university. I accidentally found out about Haskell and decided to attend a training course on stepik.org. But due to the lack of the necessary knowledge and programming experience in general, I could not fully understand what was going on and what was this all about.

Afterwards, I had courses of math logic and type theory, and after that, Ilya Peresadin and George Agapov (from Serokell) taught us functional programming in Haskell. Ilya’s maximum openness in communication and teaching greatly influenced my attitude about Haskell and functional programming in general. Together with an understanding of all the advantages of functional programming, this has led me to begin getting real pleasure using Haskell and to want to continue using it further.

Ilya’s maximum openness in communication and teaching greatly influenced my attitude about Haskell and functional programming in general.

Applying category theory to Haskell

Anton Myasnikov

Ever since elementary school, I was obsessed with the idea that our life is highly deterministic, like a game, and there surely must be some kind of strict order of actions that need to be performed in order to eventually achieve the desired result.

Like when playing games, I was interested not in specific game rules that need to be followed directly, but more in their influence on the sequence of keys that need to be pressed in order to achieve the desired result. I even had a diary in which I wrote down such sequences, in fact formalizing the process of playing.

In elementary school, where we were given the basics of math, I was surprised that when solving some simple math problems, you use abstract formulas that define the general behavior of things and then you just twist the variables, working only with their behavior. Like you don’t formulate any object and its properties directly, but only work with some specific behavior, no matter what the object is. This has had a strong influence on my attitude in contemplating many things. I was good with math at school, was sent to all possible Olympiads that I can participate in, eventually took first place in my country in physics)

In high school, I got acquainted with Pascal. I used to solve some simple math problems and then was introduced with the concept of lists and dictionaries. This fascinated me a fair amount and I played with them a lot. When I wasn’t solving needed tasks, I was writing down everything that came to my mind with these dictionaries and trying to formulate all kinds of interconnections between them.

Then I realized that this is how programming works in general, and then I wondered how it works in other languages. At the time, my vision of programming was limited to Python, C, C++, Java, and JS. And in the end, I started learning everything. One day, one of my internet-friends advised me to read a little about category theory because that’s what it’s all about, formalization of relations. Of course, in order to understand it, it took me a little while (despite the fact that everything is much simpler than it seemed to me at first), and eventually, I began to build my worldview in terms of category theory (all kinds of social relationships in the form of co-limits, logical systems, even such abstract concepts as importance, usefulness, relevance). I came to Haskell almost by accident, but I immediately was inspired because of many concepts from category theory such as functors and monads that were applied to real-world production.

Overall, it has helped me to understand a lot of things that I have been working on lately from a different angle, inspiring me to work more deeply on this topic, and in general to sort out my thoughts.

I came to Haskell almost by accident, but I immediately was inspired because of many concepts from category theory such as functors and monads that were applied to real-world production.

I would like to thank all three engineers for talking with me, and I hope you find their answers as fascinating as I did. If you want to read more about people that work at Serokell, you can find more interviews in our interview section.

If, on the other hand, this article inspired you to start learning Haskell, we also have you covered! This article by Yulia will point you to the best resources for becoming a great Haskeller, and, perhaps, after some time, you can work with us! :)