Replies: 1 comment 6 replies
-
Finalizers don't get run unless you resume or finalize. Finalization is for when you never resume a strand of raw-control that has gotten resources. This is different than garbage collection. The reference counting will drop all heap resources, but if you got OS resources or other external interactions that need cleanup, this is where finalization is important. See this paper for more in-depth information: https://www.microsoft.com/en-us/research/publication/algebraic-effect-handlers-resources-deep-finalization/.
Because that is hard to restrict from the type system perspective. Essentially you need linear types (which do exist to some degree in Koka via
Good question. Not 100% sure on this, but definitely something to look into. I believe the work on raw control predates the work on Perceus though, so maybe it just hasn't been revisited since then.
The underlying data structure is also used for finalizing
Sorry, I'm not aware of any good examples at this point. Most examples I know of try to keep an invariant that all captured continuations are run via |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all!
I would like to learn more about
raw ctl
in Koka.When I implemented effects in Lua, I had to solve the problem when to run finalizers of an interrupted (to be resumed) action. Sometimes, my handler function would return, but the resumption would be stored somewhere to be invoked later.
For this, I added a method
:persistent()
in my Lua implementation, which (I believe) somehow resemblesraw ctl
in Koka. Such a resumption would have to be manually released with:discontinue()
in my implementation, if it wasn't resumed. I had to do this because it is not forseeable when Lua's garbage collection runs, and finalizers should run in a predictable manner (and not in the context of the Lua garbage collector).The API for my Lua implementation can be found here:
Now what surprises me is that Koka requires an argument to
rcontext.finalize
. What's the purpose of that argument? I made some test:Output:
Some questions:
raw
handler exits, and not when theresume
handle gets free'd?)rcontext.finalize
(it needs to fit the action's return type, yet doesn't seem to be used other than being returned byrcontext.finalize
)?Regarding documentation of
raw ctl
, I have seensamples/handlers/unix.kk
, but I find the example a bit difficult to comprehend, and it also doesn't containrcontext.finalize
.Also possibly related:
raw ctl
#649I also just found:
Beta Was this translation helpful? Give feedback.
All reactions