HACKER Q&A
📣 weakfish

How to learn useful functional programming?


Hi,

I'm interested in learning FP, but I'd like to apply it to something as I am a generally project oriented person. To this end I'd like to try something like F# or Scala rather than Haskell and make some sort of utility - what's a good place to begin? This is coming from a Java and C background taught through university (still there).


  👤 tcbasche Accepted Answer ✓
My gateway into functional programming was via the concepts of it, things like immutability, declarative language and map/filter/reduce functions which are present in UI frameworks like ReactJS.

If you’re creating a user interface of some kind it’s a lot easier to get feedback and to actually see something working while directly applying FP concepts.

I would also recommend Typescript over JavaScript, not only for the better experience but also as there is a lot of overlap between type theory and FP.


👤 aszen
If you are interested in fp and like building web application uis then I suggest you start learning elm (elm-lang.org).

It's a beautifully small language , easy to learn with great error messages by the compiler. You can learn tk build highly interactive webpages by just going through their guide. The reason for choosing elm over scala or f sharp is that while it lacks many of the advanced features it has the essential basics of the fp world nailed down. Pure functions, function composition and currying, composing side effects.


👤 meowzero
The best way is to find a functional programmer mentor. First write an app the "normal" way. Then ask them to review your code and see how they would write it in a more functional way. That's the best way that helped me grok functional programming the fastest.

If you can't find a mentor, try creating an app with a lot of constraints: don't change state, make most functions referentially transparent, etc.


👤 clusterhacks
I got a lot of value reading through The Little Schemer and How to Design Programs to learn FP "thinking". I'm sure those two books are gathering dust over at your university library. I was unbelievably unexposed to FP in any meaningful way in my BS and MS in CS programs.

I like projects but discovered that I actually learned quite a bit just from working through short problems at Hackerrank.


👤 vemv
Clojure is a good option as well - it can be seen as FP without the type theory - i.e. a more distilled version.

It also sports a pragmatic community - web, CLI, UI etc utilities abound.


👤 mrkeen
> To this end I'd like to try something like F# or Scala rather than Haskell

What do you mean?