Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: Best way to start with functional programming?
26 points by brianchu on July 9, 2014 | hide | past | web | favorite | 13 comments
Any ideas on the best way to get started with functional programming?

I’m thinking of Clojure/ClojureScript+React, Haskell, Scala, or Elixir. Especially in the context of web or mobile.

The FP I’ve done so far is however much FP you can do with JavaScript/Python (currying, higher order functions, map/filter/reduce, underscore), and about a third of SICP (Scheme).

Most Haskellers will point you at Learn You A Haskell For Great Good.


If you go down this route: Once you start getting to chapters that don't have direct analogues in other languages, such as Functors, Applicative Functors, Monads, etc, slow down. A lot. I tried numerous times to just push through in the hopes that it would all come together, and I ended up giving up because I just dug myself further into a pit of nonunderstanding and frustration.

Give yourself time to let the strange concepts sink in. Use them several times until you truly understand them. Then move on.

FP is going to feel like programming 101 at first before you get over that initial hump. That's the way it went for me at least. The trick is seeing it through and making it past that first frustration phase. Once it clicks, it will change the way you think about programming. I'd say pick up the defacto book in one of the langs you listed and get started! I went with Elixir, and I'm hooked. Dave Thomas' Programming Elixir is an excellent place to begin.

I think it all depends on what you're background is in. If you want to be able to work on the JVM, then Clojure an Scala are going to be your obvious betts. If you're coming from a dynamic language (python/ruby/javascript) then it may be easier to take on a lisp(or other dynamic-functional language) as your fist FP language.

Scala is a great choice for people familiar to Java, and don't wan to give up all the JVM knowledge they've gained over the years.

I personally prefer Clojure/Clojurescript and the direction that the community is heading.

I took a coursera course[1] on programming languages a while back that did an introduction to ML, Racket, and Ruby. It was great to through similar problems in three very different languages. It gives you the basic information you need to weigh the costs and benefits of using a particular language in a particular context.

[1] https://class.coursera.org/proglang-2012-001/wiki/syllabus

I really liked The Little Schemer[0]. The language/syntax is a little different to Clojure but it's broadly transferable; really helped me think functionally.

I'm a total noob with this stuff but I've been really happy with Clojure (and more recently ClojureScript/Om) :)

[0] http://www.amazon.co.uk/Little-Schemer-Daniel-P-Friedman/dp/...

IMO Haskell is your best option if you want to learn functional programming (being a purely functional language) and this is the best guide to learning Haskell I've come across: https://github.com/bitemyapp/learnhaskell

It also has an irc channel that is fairly active (#haskell-beginners).

First I'll second the other comments mentioning "learn you a haskell". I dont know haskell in the way an expert does, nor do I have very much exp writing it but, I can and enjoy when I do. "learn you a haskell" does a great job at speaking in clear english and is, honestly, an enjoyable book that is pretty fun to read.

But, if you are like me, you need to understand the motivations and intensions behind things before you can really feel that you have reached understanding. You know, the big picture type stuff.

So, in my opinion, to fully understand functional programming, you need to think about what it tries to do/solve. To get here I would recommend thinking about insanely complex systems and how you would build a flexible and efficient one. To start you may think about all the objects you would need to account for, which, eventually, causes insanity. Its not the objects in the system that causes the complexity, it's their interactions. So, you may start thinking about handling all of the interactions, which is where, I believe, the solution (really method is the better word) lies.

I believe then, that the key to understanding functional programming is to understand what its related concepts are able to solve. Thinking about how to make sense of and control this shitstorm of complexity will, hopefully, shed light on why the hell something called an "applicative functor" or, <insert other crazy/weird term> even exists.

I know, I know, I am being too general... the stuff comes from category theory though, so, uh, hard not to be... but seriously, if this is at all helpful and not totally incorrect, I'd be happy to expand in more detail

if, on the other hand, it is not helpful... forget it totally, learn a language, and hopefully the concepts follow else if, I am totally incorrect... why and where did it all go so wrong? else, nop

I found Martin Odersky's Scala course on Coursera to be a great intro, and my background at that time was similar to yours. Scala itself isn't that great for learning FP since it's entirely possible to write in a Java-like style. However the Coursera class uses a functional style and the autograder ensures you do too.

I found the Functional Programming Principles in Scala course on Coursera to be incredibly helpful


The course was very challenging and I learned a lot in a very short period of time. Highly recommend it.

Also checkout the purescript book being created:


Learning a more functional language is a good idea, but you can also do more within JavaScript itself. Well after I'd been using higher order functions and Underscore, I found Michael Fogus's Functional JavaScript to be quite good. There is also JavaScript Allongé by Reginald Braithwaite, which I want to read soon. For libraries, there's Lemonad, Bilby and Fantasy Land, all of which push the boundaries of functional programming past what you get from Underscore.

Regarding Haskell, I didn't love Learn You a Haskell, but did like Learn Haskell Fast and Hard.

To be honest, best way so start FP, is to have project where you are forced to do FP :) In my case it has been a quite an awesome small selenium test-framework written in clojure I needed to use, while working for RedHat :)

Just pick a project and a most aproppriate lenguage and roll with it. You probably can guess, what language would suit your needs best, and if you haven't made up your mind about that, I (or other HN user) will probably suggest good fit for your project of choice :)

I started Clojure this week. It's really fun and it's syntax doesn't boggle my brain as much as Haskell's.

If you want an introduction to functional programming, why not go all the way with a pure functional language such as Haskell:


Registration is open for Startup School 2019. Classes start July 22nd.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact