What are scoped handlers? #539
-
I would like to understand better understand the concept of scoped handlers. The manual/book states that combining handlers creates different results based on which handler is written first. Is this related to scoped handlers? The manual section on scoped handlers is still a TODO (with a broken link). I have found several papers on this topic, but they were quite abstract/mathematical and usually didn't refer to Koka but Eff. There are examples in When implementing effect handling in Lua, I ran into problems when creating an effect that waits for I/O in a multi-fiber environment, because the sleeping (link to code) must be performed in the most inner context and not in the context where the effect handler is installed. To solve this, I made it possibe to not pass a value to the continuation but a function that gets evaluated in the context where an effect has been performed (link to code, link to docs). This seemed to be helpful for my implementation. Does something similar exist in Koka, i.e. where you can write something like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I believe this would be the recommended paper to read for both scoped effects and named handlers. First-class Names for Effect Handlers. If you don't have access to the paper via that website you can get the technical report which is very similar here: https://www.microsoft.com/en-us/research/publication/first-class-named-effect-handlers/ Additionally, your mention of passing a function to be called in the context where the effect is being performed I'm pretty sure is a problem addressed by this paper for a different language: Handling Bidirectional Effects - including appropriate typing rules I think. I'm not sure if it is something Daan has thought about or would want to add to Koka, but you could open an issue and link to the paper and propose how it would work in Koka. |
Beta Was this translation helpful? Give feedback.
I believe this would be the recommended paper to read for both scoped effects and named handlers. First-class Names for Effect Handlers.
You obviously don't have to understand the formalism to use them, but section 2 has several examples, section 3 is still pretty understandable, and you can skip to section 7 for more examples.
If you don't have access to the paper via that website you can get the technical report which is very similar here: https://www.microsoft.com/en-us/research/publication/first-class-named-effect-handlers/
Additionally, your mention of passing a function to be called in the context where the effect is being performed I'm pretty sure is a problem addressed by this pap…