Getting Started with FP

Functional Programming Code and Concepts

Brooklyn Zelenka
The Monad Nomad
5 min readDec 4, 2018

--

Recently I’ve been getting a lot of questions about the best way to learn functional programming (FP). Typically people are either looking to learn concepts to apply in their day-to-day, or are just curious what all the fuss is about. Rather than type out the same list over and over, I’m collecting my most common recommendations here.

This article is not a comprehensive “zero-to-hero” curriculum — it’s a getting started guide. Again, this is a curated list of recommendations that I give to friends and colleagues who hope to demystify this whole “functional programming” thing. Some FP concepts can seem very alien if you haven’t seen them before, and have an aura of dark magic (looking at you, monads and optics 🤨). They’re not more difficult than object oriented patterns and concepts per se, they’re just not taught as widely (though that’s changing!)

I promise that FP is not as scary or difficult as some people make it out to be, and that the resources below can help get over the initial learning hump!

Don’t let the show-offs get to you; we all have to start at the beginning 👶

Tracks

These recommendations are broken into 3 tracks depending on your tastes and goals. Given sufficient time, energy, and interest, you can work through all tracks from top to bottom, but any one of them is sufficient to get you up and running.

Ease Into It

If you’re looking to pick up a few concepts, or generally grok a more functional way of thinking, this is the track for you! This track introduces you to concepts in a friendly, conversational style, and moves into actual pragmatic code.

  1. The Little Schemer
  2. The Seasoned Schemer
  3. Clojure for the Brave and True

These are all absolutely delightful reads, and I can recommend them to everyone, regardless your level of previous experience with FP. They make fun reading on a lazy afternoon with a cup of coffee.

Working Code

Looking for getting up an running with real-world code in a fairly quick time frame? Also looking for a fairly wide overview of sub-styles?

  1. An untyped Lisp: Clojure for the Brave and True
  2. A typed ML: Haskell from First Principles (“HFFP”)

My recommendation is to read both to get a less biased view, and in the order above as a nice on-ramp. Of course it’s also okay to read just one or the other if your goals are to just learn one. Having both will lessen your conceptual bias toward one narrow area of FP.

Clojure is a pragmatic Scheme, exposing you to the LISP lineage. It’s a very nice on-ramp without being totally alien. This is a nice first introduction to FP concepts.

Haskell is an opinionated, pure (controlled effects), algebraically-typed language. HFFP is a modern book that alternates between concepts and actual code. The writing feels a little unpolished in places, but it’s a valuable read. We use it at the Vancouver Functional Programming meetup (VanFP) to as the basis for our ongoing Haskell workshops.

One of several VanFP HFFP Workshop cohorts

Theory Focused

DISCLAIMER: If you’re not excited by theory, this is not the track for you

Many people would consider this to be impractical and on hard mode, but it depends on your background and goals. That’s not a challenge to the reader! This track is focused on underlying concepts over pragmatic code. The upshot of this more abstract method is that you are better equipped to learn new languages and apply these concepts in any context.

  1. Lambda Calculus, Combinators, and Functional Programming
  2. Structure and Interpretation of Computer Programs (SICP)
  3. The Data 16 Functional Programming Course
  4. Functional Programming in Scala

I initially took this path simply because I didn’t have any mentorship and these were the books I came across… plus a bunch of other books with some overlapping material (ie: above is the short, curated version). I’m also a bit of a theory nerd. If you’re looking for a survey that explores a fairly complete foundation of the FP landscape, this is a decent way to get started.

Common Misconceptions

While we’re in here, let’s talk briefly about a number of statements that I hear semi-regularly that could use some revision:

1. “Real FP languages” have strong algebraic types (like Haskell)

FP is as broad an area as imperative languages (ex. Python, Java, and C). The original functional language was LISP (in 1958!) Haskell is sometimes held up as “the most” functional language, but that really depends on your criteria. There are languages that go further down the type-system direction than Haskell (ex. Idris, Coq) or towards declarativity (ex. Prolog and MiniKanren). Others focus on syntax, extensibility, and code-as-data rather than types (ex. Racket, Clojure), or types of concurrency (ex. Elixir, Clojure).

2. You can only write functional programs in “functional languages”

FP is primarily a style, not a list of language features. For instance, you can write C++ in a functional style. Some languages may have better support for this style than others, but it’s possible.

3. Not for systems programming or bit fiddling

Just like the previous answer, it’s not always the easiest solution or the best fit, but it’s totally possible. Haskell is famously immutable… by default (you can still enable mutability without breaking the model).

4. You need an advanced math degree

No math required! It can help, but that’s true of any type of programming (and really any STEM field). There is a lot of overlap specifically between Haskellers and math folks, though it’s in no way a prerequisite.

5. Only functional languages can support advanced type systems

Rust is an excellent example of a (primarily) imperative language with a fantastic type system. Types describe your program; they’re orthogonal to which style you’re working in. It’s true that historically most work on type systems was done in the functional realm, but it’s not a necessary condition.

Where to Get Help

I used to maintain a list of resources in a GitHub repo that I or my mentees have found useful. No guarantees that these links are still active or are up to date, but they may be a helpful for some looking to continue with further learning.

--

--