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-...