Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
kubb
22 days ago
|
parent
|
context
|
favorite
| on:
Sky – an Elm-inspired language that compiles to Go
You can just compile any tail recursive function to a function with a loop and no recursion.
1-more
22 days ago
|
next
[–]
This is in fact how Elm does it! Tail call recursion compiles to a while loop.
srean
22 days ago
|
prev
|
next
[–]
That 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.
apgwoz
22 days ago
|
parent
|
next
[–]
You _can_ do trampolines, but that is kind of infectious, or needs to be very explicit with extra code, etc.
srean
21 days ago
|
root
|
parent
|
next
[–]
Indeed. It's not very efficient though. If I remember correctly Scala does this.
adamwk
22 days ago
|
prev
|
next
[–]
Right 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
Consider applying for YC's Summer 2026 batch! Applications are open till May 4
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: