-
Notifications
You must be signed in to change notification settings - Fork 53
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
The Y combinator causes stack overflow #237
Comments
The solution is lazy evaluation, as the Y combinator is designed for a lazily evaluated lambda calculus. As fend uses a strictly evaluated lambda calculus, the Y combinator executes until stack overflow. There is a variant of the Y combinator called the Z combinator designed for strict evaluation. |
@oeb25 it‘s pretty cool how you were able to use the interrupt API for your workaround. If you wanted to make a PR to make that more ergonomic I’d happily merge it, but otherwise I think I’m going to close this issue for now. It’d be nice if fend supported lazy lambda evaluation at some point, or if lambda evaluation were implemented in a better way that doesn’t cause stack overflows like this, but I don’t think that is something I’ll implement myself anytime soon. PRs to improve the situation are more than welcome though! |
Very reasonable! 👍 Also this issue comes up when searching |
Giving an invocation of a Y combinator to
fend_core::evaluate
causesfatal runtime error: stack overflow
.The following snippet reproduces the stack overflow:
A potential user workaround is to use
fend_core::evaluate_with_interrupt
and limit the number of calculations:I don't know if this is the most optimal approach to solve this, but it seems to work for our use case.
Perhaps something could be added to make limiting the number of operations more ergonomic. This is of course a bit of a special input, but when exposing fend to user inputs it's good to be a little careful.
Feel free to close this if you feel like it! There exists a workaround, so I completely understand if you would rather not change the API. Either way, thanks for making fend!
The text was updated successfully, but these errors were encountered: