3 ms·
Recursion is only a bad idea in languages with poor support for recursion, it's not difficult to write efficient Haskell code which produces good assembly with
by axman6 9y ago
Recursion is only a bad idea in languages with poor support for recursion, it's not difficult to write efficient Haskell code which produces good assembly with fairly obvious recursive algorithms. Optimisations like stream fusion and libraries like foldl also contribute to really good code generation (not guaranteed and also not generally applicable optimisations, but certainly helpful)
- mr_overalls 9y agoDoes Haskell provide tail-call optimization or similar optimization to take away the stack-space costs of recursive function calls?
- Terribledactyl 9y agoGHC can, if you want it to. It's hard to answer in a general way because of the laziness, and you can always force evaluation. But then you rob GHC of potentially better optimizations, like never executing it in the first place. This SO does a good job of explaining the trade offs. https://stackoverflow.com/questions/13042353/does-haskell-have-tail-recursive-optimization https://stackoverflow.com/questions/13042353/does-haskell-ha...