DEV Community

Cover image for Introduction
Benoit Ruiz
Benoit Ruiz

Posted on • Edited on

Introduction

Hello and welcome!

Today I'm introducing a new series about Functional Programming, or FP for short.

Functional Programming is an amazing world, but it can be quite challenging to walk on these lands and learn its concepts without feeling overwhelmed. At least that's how I felt when I discovered this paradigm.

When trying to learn FP, one of the first walls we bump into is the vocabulary. Functor, monad, algebraic data types, referential transparency, side-effects, higher-kinded types. All these buzzwords sounded mystical to me. It took some time (several years actually) to learn what they mean, how I could use them, and what were the relationships that tight them together.

Although there are quite a lot of articles about functors, monads, and the likes, I think there is still a lack of content regarding all the "surroundings". More specifically, there are root concepts that are essential and used everywhere when doing FP.

In this series, I will try my best at introducing and explaining the following:

  • What is FP, and why we should learn and use it
  • Function composition and higher-order functions
  • Declarative vs imperative
  • Side-effects
  • Function purity and referential transparency
  • Data immutability
  • Function currying, partial application and tacit programming
  • Parametric polymorphism (aka "generics")
  • Inversion of control
  • Algebraic Data Types (ADTs)
  • Kinds and higher-kinded types (HKTs)
  • A word on category and set theories
  • Algebraic structures and type classes
  • Bonus (possibly): map filter reduce, tagless final, optics, transducers

I will not talk about (or maybe briefly) functors, monads, applicatives, etc. as I believe there is already a lot of great material out there explaining these great tools.

Hopefully by the end of this series, you will have all the means necessary to walk on these lands peacefully.

Who am I?

Before diving into the subject, let me tell you about my experience with FP, and what you can expect from the quality and depth of this series.

My adventure began about 4 years ago, in 2017. I am still climbing the learning curve, I haven't mastered this paradigm. Though, I don't feel like I'm at the bottom anymore, which is nice.

I have been applying these concepts in TypeScript and Scala for the past years, as they are the main languages I have been using. I have seen the limitations of TypeScript compared to Scala or Haskell for example. Nonetheless, it is still possible to do FP in TypeScript, although it may feel less natural than with a language that has built-in FP concepts.

I have read a lot of articles and blog posts, and I still do. These are mainly the ones that helped me in this journey:

I started reading Category Theory for Programmers (Scala Edition) by Bartosz Milewski a few years ago, although I never finished the book. I stopped at around 30%. I would not advise reading this book at the beginning of the journey. As the book name suggests, there is a lot of theory in these pages! That being said, once you have grasped the main concepts, it is definitely a good book to dive deeper into the essential "components" that make FP possible.

Since my learning revolves mainly around TypeScript/JavaScript and Scala, the examples I will share will be written in these languages. However, this should not be an issue as the majority of these concepts are language-agnostic and can be implemented, or applied, in pretty much any language.

So, as you see, I am not some FP guru. I am still not able to write Haskell code like it's child's play. Some of my explanations may be incomplete, or partially wrong. If that is the case then please leave a comment so I can learn and fix these mistakes.

I may lack some formality in my explanations, though I think it is better to present these concepts in a more informal way, if one wants to convince people to learn and try FP.

I hope this series will help you dip a toe in the water, and convince you that Functional Programming is not that mystical after all!


Photo by Xavi Cabrera on Unsplash.

Top comments (0)