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

Add a primitive for laziness/call-by-need semantics #5564

Open
anka-213 opened this issue Jan 31, 2025 · 1 comment
Open

Add a primitive for laziness/call-by-need semantics #5564

anka-213 opened this issue Jan 31, 2025 · 1 comment

Comments

@anka-213
Copy link

Is your feature request related to a problem? Please describe.
Some algorithms and tricks are only possible in pure languages when you have access to laziness/memoized thunks. See e.g. Okasaki's "Purely Functional Data Structures", many of which depend on laziness to get their desired asymptomatics. Or tricks like using info about the final data structure to put info in leaves

Describe the solution you'd like
I would like to have some kind of primitive to create a memoized thunk/lazy value. A signature that was proposed on discord is the following:

memo : '{} a -> '{} a

The lazy value needs to be pure, since it would be a complete mess otherwise.

It might also be the case that some of the rules on recursive definitions would need to be loosened if the primitive is used, to actually allow self-referential lazy definitions, but I'm not completely sure.

Describe alternatives you've considered
There are other possible interfaces that could be used to introduce laziness. I haven't completely thought through the options.

Without some way to get laziness, one would have to make do without the improved asymptomatics of those algorithms.

Additional context

This post by Edward Kmett lists a few more things that are difficult or impossible to do without laziness: https://www.reddit.com/r/haskell/comments/5xge0v/comment/deia53t/

@anka-213
Copy link
Author

anka-213 commented Feb 1, 2025

Another option would be to have a separate type for lazy values. This might have the disadvantage of not being able to use it in as many places though.

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

No branches or pull requests

1 participant