4 ms·
Great work :). Go doesn't have TCO. That means functional languages (no for loops) could blow up the stack. How did you solve that?
by submain 6mo ago
Great work :). Go doesn't have TCO. That means functional languages (no for loops) could blow up the stack. How did you solve that?
- kubb 6mo agoYou can just compile any tail recursive function to a function with a loop and no recursion.
- adamwk 6mo agoRight but recursion is only a smaller part of why the optimization is important. It means tail-called functions still build on the stack and long function chains—as is common with fp—can overflow
- 1-more 6mo agoThis is in fact how Elm does it! Tail call recursion compiles to a while loop.
- deleted 6mo ago[deleted]
- srean 6mo agoThat does not address the use case where I find tail recursion most tempting. That would be mutually recursive functions. If the function can be written as an idiomatic loop I probably would do so in the first place.