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

Is the Resource effect going to make a return? #7

Open
expipiplus1 opened this issue Apr 12, 2020 · 1 comment
Open

Is the Resource effect going to make a return? #7

expipiplus1 opened this issue Apr 12, 2020 · 1 comment

Comments

@expipiplus1
Copy link

I see it was removed when things were rewritten to use delimited continuations.

@lexi-lambda
Copy link
Contributor

The answer is: sort of. Resource is not really an algebraic effect; rather, it is a collection of operations for installing handlers that should be invoked on winding/unwinding. I therefore intend to support bracket-like operations, but they will likely not belong to any particular effect, they will simply always be available. (You can think of them as being kind of like handle, which is always available in a similar way.) Of course, if you want to use those operations to manage IO resources, you will still need the IOE effect.

Getting all this right in general is rather tricky. For example, suppose we implement a withFile operation, then write this:

withFile path mode \handle ->
  foo handle <|> bar handle

The use of <|> is a use of the NonDet effect, which generally resumes the computation multiple times, once for each branch. But by the time we resume the computation to execute bar handle, foo handle has already returned, so handle is already closed. Oops.

In general, it is incredibly difficult to statically prevent all these possible interactions, so you have to enforce some properties dynamically—the above program should probably crash with a runtime error. That’s rather unsatisfying, but the alternative is for it to just crash later, when it tries to do something with a closed Handle. When you start also considering async exceptions, things rapidly become a nightmare.

So the answer is: yes, there will be support for these operations in some capacity, but getting all the details right is remarkably subtle, and I have not yet decided what precisely the API will look like.

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