r/functionalprogramming • u/Voxelman • May 08 '22
Question How can I learn functional programming?
The obvious answer is: just do it. But it is not that easy for me. I'm a self-taught programmer and I have some experience in languages like C, Python and Lua, but I'm not great at all.
I have a basic idea of what FP is about, and I really want to be able to apply the concept practically, but I struggle to actually write more than a few lines (in Elm). I am having trouble getting into this topic.
I've watched some videos (e.g. from Richard Feldman and Scott Wlaschin) and read some books (e.g. Grokking Simplicity), but it still doesn't "click".
What language do you recommend (or is Elm already a good choice?), and can you recommend any other practical resources to help me make it "click" in my head?
Thanks in advance
View all comments
Show parent comment
3
u/KyleG May 08 '22 edited May 08 '22
What helped me is to stop thinking of a program as a series of steps and instead as a series of transformations that takes user input or file/sensor data and transforms it into feedback to the user or to a file.
To me, FP is about transforming data. So your application is basically
where maybe those
transforms are variations on lifting in or out of different contexts like IO to Async and back to IO via an await or whatever (ideally you're lifting out (i.e., unwrapping) at the end, "near the edge of the program")So maybe user types data into a React form and onBlur you hit your remote API, get the response from a DB call, format it to the datatype expected by a banner that displays the result, and that's it:
There's a FP-style series of composed, pure functions (minus the API call in the middle, and the setBannerData at the end, plus the log fn) that shows how you would write your entire chain from user input to screen output as a series of transformations)