News for hackers. Stuff that matters.
Re:Functional Programming with Bananas, Lenses, Envelopes an... by siraben on Wednesday August 05, 2020 @08:27AM (#24060034)
Yes, overuse of abstractions is a problem, however I'd argue from experience that using recursions schemes in FP allow us to be free from "the goto of FP", that is, direct recursion. You can of course still write programs in directly recursive style, then later replace them with a mathematically equivalent program that uses recursion schemes, which is essentially refactoring. Similarly, I can easily generalize a program by replacing, for instance, map on lists with fmap, and now it will work for any functor.

I think what adds to the value of FP's abstractions is how they have mathematical (viz. categorical) laws in mind, which make them precise and elegant.

Anyone know if the same can be said for design patterns? It requires more classes to be added, more boilerplate, which definitely adds to the complexity.

Re:Functional Programming with Bananas, Lenses, Envelopes an... by siraben on Wednesday August 05, 2020 @08:41AM (#24060150)
Also, these laws are immensely valuable to compilers. The Haskell foldr/build rewrite rule allows for intermediate lists to be eliminated altogether[0], so you can write

  sum (map square [1..n])
and the compiler will remove the intermediate list altogether, putting a tail-recursive loop in the expression's place.

[0] Paper on deforestation https://link.springer.com/content/pdf/10.1007%2F3-540-19027-...