2 ms·
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
by siraben 6y ago
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-9_23.pdf https://link.springer.com/content/pdf/10.1007%2F3-540-19027-...