4 ms·
You may find it interesting to study FP a bit more, because recursion, when understood, is pretty universally felt as way more readable than its imperative alte
by kephasp 4y ago
You may find it interesting to study FP a bit more, because recursion, when understood, is pretty universally felt as way more readable than its imperative alternatives.
I also usually find currying extremely practical and easier for me when it's available.
Most of us that only use FP in our day job don't do it out of masochism, AFAICT. I certainly don't.
- grumpyprole 4y agoYes, recursion can be used to define a function inductively, just as we would in maths. However, recursion is the "GOTO" of functional programming and we prefer to used structured programming if possible, e.g maps/folds/unfolds etc. That would be a better reply for the parent post.
- kephasp 4y agoOf course I use combinators more often than I write recursive functions. But if someone finds recursion less readable, I still think they're missing something crucial. And I don't think recursion is a GOTO that should be avoided. It's a useful tool that's easy to read and reason about.
- grumpyprole 4y agoI agreed with your parent post and upvoted you, but too many inexperienced with functional programming claim it is all (or too much) recursion. I think this should be challenged. Yes recursion is a useful tool, just like GOTO and is sometimes necessary or more practical. But it is better to e.g. use a fold if you can because that further constrains and aids reasoning. For example, a fold will always terminate unlike general recursion. I recommend looking into recursion schemes, if you aren't familiar with them.
- kephasp 4y agoI read about them a few times, but I never saw them proposed as the main access to recursion. Are there examples of that use?
- grumpyprole 4y agoIf you don't mind some advanced Haskell, these slides have plenty of examples: https://github.com/willtim/recursion-schemes/blob/master/slides-final.pdf https://github.com/willtim/recursion-schemes/blob/master/sli...