2 ms·
How do you write a function to sum a list of a billion elements in Haskell? What would happen without tail call elimination?
by Evbn 14y ago
How do you write a function to sum a list of a billion elements in Haskell?
What would happen without tail call elimination?
- eru 14y agoWith foldl', of course. If you don't have tail recursion elimination, foldl' would have to be provided as a built-in. Summing up numbers is inherently strict, so you'd want tail call elimination for that. But functional mainstains, like say, map or filter are usually not implemented with tail recursion in Haskell, because that would be too strict and would break on infinite lists.