Learning and groking recursion

I’ve started learning functional programming in July 2016. Actually I wanted to learn Elm because it looked to me like a powerful web development language (and I’d head some good things about Elm from very experiences Haskell programmers. One word that drew my attention was : the code written in Elm is very elegant.

I “practice” Elm only when I am at home, in my free time (which basically means, when the 3 young kids are asleep, at night).

I soon discovered the Functional Programming world, which was not really my first intention. But I thought, well, let’s go for it, let’s be “mainstream” J

That’s where things got a little more complicated than I had expected. As many will say, it is a change of paradigm, for people like me, who did some PHP, SQL, ASP 3.0 or a little “copy/paste JavaScript” before.

When this change of paradigm was done in my head, things became really smooth and fun.  But then I decided to dive into recursion (I had not really notice that a List.map IS actually a recursion).

Things again became complicated. I was told to read some books to grasp the “recursion” thing, but it was hard. I started reading “The little schemer”, I understood this very simple and fun book, so I thought it was ok.

Then I decided to actually write a recursive function of my own, and I fell lost. I didn’t understand what I was not doing that was in the book. I decided to stop looking at the book, and to try, and try and try, again and again, with very different exercises that I invented. It was hard, the solution was never easy to find, sometimes I felt like I was an expert in recursion, and sometimes I felt like I would never be able to do it. I thought it was a good thing that I was not paid to program.

Guess what? Yesterday I began reading Evan Czaplicki’s book Functional Programming in Elm. And he describes, not exactly in the same way, the pain that he had when he was a student, learning and practicing recursion. Wow, how good it felt to hear that.

Especially when he compares it to leaning the For loop, and it reminded me that, yes, at the beginning it was hard for me to grasp the For loop. But I had forgotten that I had to learn it long ago. Now it is feels so obvious.

In this book, Evan also gives some advice about how to understand recursion when you try to apply it. It looks like some “dumb” advice, coming from an expert in this field. But guess what? That was the same tricks that I had found myself. Which means that what we think is just something that we use because we are not experts, is also used by experts! How good it is to hear that also!

One last thing. Evan says that we the existing functions of Elm, we don’t really have, most of the time, to invent our own recursive functions in Elm. Was I wasting my time trying to learn that? Trying to re-do the functions of the Elm List library? Was I the only one on earth trying to do that?

Guess what… Later in the book, Evan writes that it is a very good thing to learn recursion, and the best way to do it is, for instance, trying to write the recursive functions from the Elm List library.

What I learned :

  • Don’t be afraid of what you try.
  • Prefer practicing again and again than reading books.
  • Consider you learned something not when you understood what was written in a book, but when you can actually do it.
  • Invent your own exercices.
  • Try to dig deeper than the surface.
  • Be your own master.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s