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

Memoize on Resource is weird #1620

Closed
djspiewak opened this issue Jan 24, 2021 · 2 comments
Closed

Memoize on Resource is weird #1620

djspiewak opened this issue Jan 24, 2021 · 2 comments

Comments

@djspiewak
Copy link
Member

Or rather, it's weird if you use the results. For example:

foo.memoize.flatMap(r => r.use(pure) *> r.use(pure))

The second use will end up accessing the resource after the finalizers have already run. It's not entirely clear what the ideal semantic here, but this seems… not great. One possible answer would be that the memoization needs to be re-run once the first use happens, but there's no way to do this generically, since memoize is implemented as a generic combinator on Concurrent.

This in turn raises an interesting question: is this an early indication that Concurrent[Resource] just doesn't make sense? Are there other such examples? Can we quantify the "weirdness" in terms of laws?

@armanbilge
Copy link
Member

is this an early indication that Concurrent[Resource] just doesn't make sense

I'm not sure. I feel like whether Concurrent[Resource] makes sense is being conflated with whether memoize can be implemented generically.

I don't remember seeing laws for memoize, but it seems like some could be written in terms of Ref. Namely, that the effect in question is run at most once, since that is what memoize is fundamentally about AFAICT.

So long as it is possible for Resource to implement said memoize lawfully, then I'd say Concurrent[Resource] makes fine sense.

@djspiewak
Copy link
Member Author

Arman went and fixed this because that's what he does

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

2 participants