
Ask HN: How did you learn functional programming? - xupybd
Functional programming is making its way into mainstream programming. Most of us know some basics and use them day to day but most don&#x27;t have a deep understanding of functional programming. For those of you that do how did you get there?
======
dgb23
IMO there are two different types or schools of functional programming.

There is the Lisp/dynamic typing (Scheme, Clojure, Erlang, Elixir, Julia...)
style:

Avoiding state from a correctness perspective is a basis but not necessarily
the end-goal here.

The primary goals are to decrease complexity and coupling and increasing
malleability, composability and empowering through interactive development
(REPL).

And the statically typed (Haskell, OCaml, Scala, F#...) one:

Here there is a much stronger focus on internal consistency of programs, which
enables stronger mathematical soundness and reasoning.

Note that this distinction is only in part equal to the general dynamic vs
static one. Typing discipline is not completely orthogonal to the paradigm
(for example imperative vs functional).

I personally am very much in the camp of the former and only have superficial
understanding of the latter.

I always recommend SICP because it was the book that helped me 'get it'. But
there might be more modern alternatives.

A question you can ask yourself: How do you approach programming?

\- Your program design is usually very high level. A graph of ideas. Then you
want to interactively and iteratively discover requirements and check
assumptions. You strive for simplicity and want to gradually achieve
robustness, only where needed.

\- You think in terms of laying out rules and form. You want to infer the
connections and implementations given those rules. You gain satisfaction from
solving puzzles upfront to enable strong run-time guarantees and sound
abstractions.

If you lean stronger towards one of these thinking models then you might
consider diving deeper into its respective typing discipline.

------
faical
I learned functional programming many years ago, by reading the book COMMON
LISP: A Gentle Introduction to Symbolic Computation by David S. Touretzky [1].
Incredible book, super beginner friendly; the chapter on Recursion in
particular is one of my favourites. :)

[1]
[https://www.cs.cmu.edu/~dst/LispBook/book.pdf](https://www.cs.cmu.edu/~dst/LispBook/book.pdf)

~~~
deepaksurti
+10 for the chapter on recursion. It is not only a must read but probably the
only thing one needs to read to understand Recursion.

I suspect Christopher Nolan read the chapter on recursion before writing
Inception :-)

------
hackermailman
[https://cs.uwaterloo.ca/~plragde/flaneries/](https://cs.uwaterloo.ca/~plragde/flaneries/)
the 'teach yourself racket' small book covers Hof, Lambdas, pattern matching,
then you can take his other short course on Agda to learn dependent types.

Or try ocaml
[https://www.cs.cornell.edu/courses/cs3110/2020sp/textbook/](https://www.cs.cornell.edu/courses/cs3110/2020sp/textbook/)

------
austincheney
Self taught more than a decade ago. JavaScript is my first programming
language. In the language you can expressively use and pass around functions
anywhere no differently than primitives.

Nesting functions provided a necessary structure that both includes
containment and reference. At the time JavaScript did not have block scope,
modules, or native classes. Also taking advantage of lexical scope in favor of
prototypes/inheritance resulted in slightly faster execution. Really, for me,
it was more about taking full advantage of lexical scope more than concern for
what the function returned as a value.

I would see other people attempt to fake classes in the language and it was
atrocious. First of all the code was ugly, but worse is that there absolutely
no benefit to this. Clearly these other developers were just just trying to
mimic some conventions they use in other languages without learning how to
organize their code. That is the opposite of elegant and I didn’t want
anything to do with it.

------
kasey_junk
I actually learned functional programming first. The first language I spent
any considerable amount of time with was Scheme, working through college
textbooks and then later taking college courses.

------
muzani
There's a 1.25 hour class on Pluralsight that covers it:
[https://app.pluralsight.com/library/courses/functional-
progr...](https://app.pluralsight.com/library/courses/functional-programming-
big-picture/)

It's easy enough to pick up in an evening and explains it very well. It's
behind a paywall but there's a free trial.

------
girishso
I tried learning FP with Clojure, but could not get my head around all the
parenthesis. Somehow came across Elm, it's documentation is very beginner
friendly (and so is the language itself). If you want to learn typed FP, Elm
is the way to go. But typed FP is little difficult to pick up.

These days I would recommend Elixir, if you want to a hang of untyped FP.

------
dave_sid
If FP is going to survive within mainstream programming then it’s the “very
basics“ of it that will carry it forward. It’s the difficulty of understanding
and application OOP that is leading to OOP’s demise. Unfortunately, and
incorrectly, the need for a “deep understanding” of either paradigm is not a
factor that will lead to mass adoption.

~~~
xupybd
I agree but think I'd benefit from a deep understanding of the tools I use
inorder to correctly reason about the solutions I apply those tools too.

I think mass adoption appears to be happening. I don't know why it is merely
an observation.

------
e19293001
Study lambda calculus first.

An Introduction to Functional Programming Through Lambda Calculus

Book by Greg Michaelson

It's amazing it was published 31 years ago (1989) which shows that it's a
timeless book to read.

This has been referenced from discussions a couple of times:

[https://news.ycombinator.com/item?id=6093386](https://news.ycombinator.com/item?id=6093386)

[https://news.ycombinator.com/item?id=3851352](https://news.ycombinator.com/item?id=3851352)

[https://news.ycombinator.com/item?id=11578961](https://news.ycombinator.com/item?id=11578961)

[https://news.ycombinator.com/item?id=10714770](https://news.ycombinator.com/item?id=10714770)

[https://news.ycombinator.com/item?id=773369](https://news.ycombinator.com/item?id=773369)

[https://news.ycombinator.com/item?id=16973546](https://news.ycombinator.com/item?id=16973546)

[https://news.ycombinator.com/item?id=14395620](https://news.ycombinator.com/item?id=14395620)

[https://news.ycombinator.com/item?id=13211603](https://news.ycombinator.com/item?id=13211603)

To quote a SO answer on why learn lambda calculus[0]:

If you want to program in any functional programming language, it's essential.
I mean, how useful is it to know about Turing machines? Well, if you write C,
the language paradigm is quite close to Turing machines -- you have an
instruction pointer and a current instruction, and the machine takes some
action in the current state, and then ambles along to the next instruction.

In a functional language, you simply can't think like that -- that's not the
language paradigm. You have to think back to lambda calculus, and how terms
are evaluated there. It will be much harder for you to be effective in a
functional language if you don't know lambda calculus.

[0] - [https://stackoverflow.com/questions/114581/how-helpful-is-
kn...](https://stackoverflow.com/questions/114581/how-helpful-is-knowing-
lambda-calculus/114701)

~~~
non-entity
Do you have to be strong in other forms of calculus prior to learned lambda
calculus?

~~~
Jtsummers
Calculus (from math) is not related to lambda calculus, they can be learned
independently of each other.

------
k0t0n0
Start with Clojure then move to f# then Haskell.

