Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiling with thunks #978

Open
johnynek opened this issue Mar 31, 2023 · 0 comments
Open

compiling with thunks #978

johnynek opened this issue Mar 31, 2023 · 0 comments

Comments

@johnynek
Copy link
Owner

In a pure total language, evaluation order in strict vs lazy gives the same result, although the runtime or space requirements may be different.

We support recursion, but not all recursion can be expressed in a tail-recursive manner. In order to make non-tail-recursive functions safe, we could compile those using thunks for the recursion, pushing the stack space consumption into allocated memory rather than directly on the stack.

An important non-tail recursive function is fold-right. Although, we can implement that one by doing reverse then implementing fold-left, but that does lose some of the short-circuiting that we get in a few cases with fold-right (e.g. checking if all elements or any element of a list satisfies a predicate).

This relates to #966 since doing that potentially deoptimizes a lot of safe recursions into fold-right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant