r/ProgrammingLanguages • • Jan 18 '26

Why not tail recursion?

In the perennial discussions of recursion in various subreddits, people often point out that it can be dangerous if your language doesn't support tail recursion and you blow up your stack. As an FP guy, I'm used to tail recursion being the norm. So for languages that don't support it, what are the reasons? Does it introduce problems? Difficult to implement? Philosophical reasons? Interact badly with other feathers?

Why is it not more widely used in other than FP languages?

76 Upvotes

117 comments sorted by

View all comments

Show parent comment

3

u/Axman6 Jan 19 '26

By taking the time to understand how your code is evaluated. It’s not hard, it can be done on pen and paper or a text editor more easily than most languages, but most people don’t spend the time to learn what they’re actually writing. Those sorts of mistakes are ones that all beginners make but it’s extremely rare for Haskell developers with just moderate experience.

0

u/tmzem Jan 19 '26

Maybe not. But it still expends some time thinking about aspects of your algorithm that would be trivial otherwise. If I use an imperative loop, I never have to convince myself that loop-local state has runaway memory consumption.

In Haskell, I only get that same peace of mind if I make use of some kind of iteration/folding construct that is guaranteed to have O(1) memory consumption, no matter the amount of iterations performed. Yet information about the O(_) complexity in time/space is curiously often absent in Haskell documentation.