Explicit tail calls #4840
Closed
cGuille
started this conversation in
Ideas & suggestions
Replies: 1 comment 4 replies
-
This isn't something that the compiler can do as tail call behaviour is a factor of both the compiler and the runtime. Just the compiler isn't able to guarantee any particular behaviour. You could make a linter tool to give you good-enough hints, that could be a fun project and useful for folks who are learning! You'll perhaps find understanding this becomes trivial as you become used to working in the functional style, which may make building a static analysis tool not so interesting. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I am quite inexperienced when it comes to fully functional programming.
When using recursion, tail calls seem to be very important for recursive functions. They would be the difference between a function that can be used with large input data or one that can not.
That a function is tail call recursive might be immediately obvious to experienced functional programmers, but I think it is not to many of us.
If you have tips or tools to easily check that your recursive functions are tail recursive, feel free to share them; they could be an alternative to this proposal.
Otherwise, since Gleam is super supportive of the developer experience, would you think it a good idea to add "something" to a function to explicitly require it to use tail call recursion?
I don't know about the syntax or name of the operator, maybe adding a
@tail_recursive
attribute to the function?Using the tour's example code, it would look like:
Or maybe the opposite, an attribute to deny non-tail recursive calls?
It would be a compile error to define a function marked as tail recursive while making a non-tail recursive call, which means that:
Or can/should it be implemented in userland?
Beta Was this translation helpful? Give feedback.
All reactions