HACKER Q&A
📣 dprophecyguy

Hey Functional Programmers, how did you learn functional programming


Hi Everyone, I am not here to start a debate about OOPS vs Functional programming. So if you are not doing functional programming and don't like it simply ignore this thread.

This thread is for everyone who uses functional programming in their day to day life and have gone through the struggle of building mental models about functional way of doing things.

I am not looking for a guide to learn haskell syntax and any other programming syntax. I am looking for how to really learn functional programming how to build the mental models in order to think functionally. So that even if a language is not functional by nature, I can model my functions and data in functional way of building programs.

I myself write JS and Typescript for living and i came across this library https://github.com/gcanti/fp-ts

But not even 1% of this library make sense to me. So if anyone of you have gone through the struggle and overcome it and using fp in your code. Please share the knowledge to fellow learner.

Thanks <3 !!


  👤 JoelMcCracken Accepted Answer ✓
So, this is going to be an uphill battle for you. I suggest you actually learn Haskell first, and then you'll be able to apply its lessons to TypeScript.

Its tricky because these are patterns that are familiar in Haskell but are not really taught in other settings.

Additionally, to really learn these, you need to experiment with them. Use them. etc. That's pretty hard to do if the learning resources are mostly in haskell and you don't really understand it.

Alternatively, this might help: https://github.com/MostlyAdequate/mostly-adequate-guide

Also alternatively, what I would do is just go slowly through the fp-ts code. Look at it a piece at a time and slowly grow your understanding.

This may also help https://www.amazon.com/Domain-Modeling-Made-Functional-Domai...


👤 gradschool
Your profile says you like doing things your own way, so the best way for a person of your disposition to internalize functional programming concepts is to make up your own functional programming language and write an interpreter for it. Without all the bells and whistles, the interpreter amounts to a stack machine. You can skip the literature survey if you want because whatever you invent will be similar to what's been done. Your first version should be so bad it's embarrassing. The important thing is to have it up and running and then think about improving it. Don't overdesign it because if you make a bad decision and have to redo it you'll learn even more. Start with the usual functional programming combinators (map, fold, etc.) and by the time you've worked your way up to monadic i/o you'll understand that stuff as well as anyone.

👤 manx
I learned Scala, and slowly used more and more immutable data structures. The rest followed naturally.

I think working with immutable data structures is the key to functional programming. It leads to writing more pure functions and changes your thinking about software architecture.


👤 samhh
fp-ts is hard to learn. Its docs, whilst improving, aren't great and it's applying pure functional concepts to a language which isn't designed for it. The outcome is surprisingly good but it's hard to understand as a newcomer why certain design decisions have been made, or what patterns are and are not idiomatic.

I'd recommend learning Haskell in your free time. It's a major paradigm shift but once it clicks you'll find it a lot easier to translate those concepts into fp-ts.

I went through this journey a couple of years ago, and now write heavy fp-ts code full-time - including maintaining fp-ts-std[1] - as well as some paid Haskell gigs on the side. Do feel free to reach out if you want any guidance at all, you'll find my email on my personal site[2]. The FP Slack is also a great place to ask for help with anything FP, including fp-ts - if you send me an email I can have an invitation sent to you.

[1]: https://github.com/samhh/fp-ts-std [2]: https://samhh.com


👤 visox
For scala i did Oderskie's course on coursera. Helped a lot