hasura/eff

Is the Resource effect going to make a return?

expipiplus1 opened this issue · 1 comments

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

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.