Functional programming for beginners
Tags: functional, beginners
Published: 2018-03-23 16:30:35

---
title: Functional programming for beginners
published: true
tags: fp, functional, beginner
canonical_url: 
---

Recently, I attended [Manuel Chakravarty](http://justtesting.org)’s YOW! night talk titled Demystifying Functional Programming, which inspired me to write this post.

From my work, I gained some intuition that trying to teach <abbr data-toggle="tooltip" title="functional programming">FP</abbr> by explaining the theory first didn’t work well. In hindsight, this seems almost obvious. A lot of us were taught math this way and sadly it has left many of us misunderstanding math or even despising it, even though it might be very useful in their chosen field<sup>1</sup>.

What worked better was to show how elegantly FP solves many problems we were focusing on; one that required a use of parsers or another for which we were using reactive programming to process and analyse large quantities of data in real-time. These were some of the concepts I’ve learned in Haskell and was able to apply in Scala. They were harder to implement in the imperative way, which only complected them and that also made them harder to understand.

My intuition really aligned with the content of Manuel’s talk. With his long-time experience and commitment to working with and teaching Haskell, Manuel discussed what we can do to advance FP from the stage of innovators and early adopters to early majority<sup>2</sup>, which he summarised as:

- Examples first
- Teach design patterns
- Tight feedback loop
- Visualisation can be an effective tool

Another seasoned Haskeller Gabriel Gonzalez has written some great advice for Haskell beginners<sup>3</sup>, in which he recommends to:

- Avoid big-design-up-front
- Start programming at term-level (using simple values and functions)
- Build something useful

If you gave Haskell a try, but still find it too intimidating, I would recommend you having a look at Elm. Elm (which itself is written in Haskell) is a very small language in terms of the size of its grammar, which makes it a perfect fit for beginners. Not only is it very good at all the points above, it can also compete with other front-end frameworks like React. The whole notion of languages being general-purpose can be quite misleading<sup>4</sup>, Elm is intentionally not a general-purpose language<sup>5</sup> and it serves its intended purpose very well. You don’t have to take my word for it though, instead, you can watch a [talk by Richard Feldman](https://youtu.be/EStQa0QsUb8), who’s been using both React and Elm side-by-side in production for over a year.

Cool, you got me, but…

## Where do you start?

![Welcome to Elm](https://tzemanovic.github.io/images/elm-grove.jpg)

Of course, not everyone learns the same way. As a general recommendation I would say:

Try not to learn too many things at once, keep things simple. This is especially important if you come to FP **with prior experience** from imperative languages, which doesn’t translate well into FP concepts. You might have heard functional programmers say that when you start, you will have to unlearn things, and this is what they’re referring to. Honestly, you will need patience, because everything might seem slow at first. That’s okay, don’t give up and keep at it!

Try to find someone who already has experience with FP and ask them for help with writing something simple. When you see FP applied to solving a real problem, you are very likely to learn faster. There are people who say they were able to pick up Elm this way within a week, but don’t set your expectations too high. Once again, everyone’s learning path is different. Look for FP [meetups](https://www.meetup.com/) in your area, join [Elm on Slack](https://elmlang.herokuapp.com/), read the comprehensive [Elm Guide](https://guide.elm-lang.org/). Don’t start trying to write a full-blown single page app, there are ways to [gradually introduce Elm at work today](http://elm-lang.org/blog/how-to-use-elm-at-work). Or you can just play around [directly from your browser](http://ellie-app.com/), you don’t even have to install anything.

Lastly, don’t be afraid to make mistakes, for it’s an important part of any learning process.

* * *

1. [Leslie Lamport: Why Don’t Computer Scientists Learn Math?](https://lamport.azurewebsites.net/tla/math-knowledge.html)↩

2. [Wikipedia: Diffusion of innovations](https://en.wikipedia.org/wiki/Diffusion_of_innovations)↩

3. [Gabriel Gonzalez: Advice for Haskell beginners](http://www.haskellforall.com/2017/10/advice-for-haskell-beginners.html)↩

4. [Bret Victor: What can a technologist do about climate change? A personal view.](http://worrydream.com/ClimateChange/#tools-modeling)↩

5. [Evan Czaplicki: On “General-Purpose” Languages](https://github.com/elm-lang/projects/blob/master/notes/on-general-purpose.md)↩