<p>In Java in addition to <code>catch</code> there is also <code>finally</code>, this is very important to make sure resources get cleaned up. I believe <code>dynamic-wind</code> for <code>call-cc</code> is similar to this. According to <a href="http://okmij.org/ftp/continuations/implementations.html#dynamic-wind" rel="nofollow noreferrer">this</a> <code>dynamic-wind</code> can be written using delimited continuations. Because algebraic effects can can express delimited continuations, does that mean that we can write a <code>finally</code> like construct using algebraic effects and handlers, that allows us to safely handle resources?</p>

CC BY-SA 4.0
2019-12-20T16:58:01.990Z
If you have `catch` but not `finally`, you can always write a `catch` block that merely performs cleanup and re-raises the exception. Perhaps something similar could work with algebraic effects? The non-linear use of the continuation could be problematic, though.
isekaijin
CC BY-SA 4.0
2019-12-20T20:01:53.167Z
Yes I am worried about the fact that with algebraic effect handlers you can call the continuation zero, one or more times.
Labbekak
CC BY-SA 4.0
2019-12-22T13:21:21.797Z
There is a recent arxiv paper by Danel Ahman and Andrej Bauer: https://arxiv.org/abs/1910.11629 that describes "runners" which differ from handlers and have an interface that uses "finally" clauses. I'll just leave this as a comment since Andrej is a frequent user here and so is likely to give an answer.
Max New
<continuations><algebraic-effects>
"finally" for algebraic effects and handlers
Labbekak
# "finally" for algebraic effects and handlers

(Asked by: username_0 on 2019-12-20)

In Java in addition to `catch` there is also `finally`, this is very important to make sure resources get cleaned up. I believe `dynamic-wind` for `call-cc` is similar to this. According to [this](http://okmij.org/ftp/continuations/implementations.html#dynamic-wind) `dynamic-wind` can be written using delimited continuations. Because algebraic effects can can express delimited continuations, does that mean that we can write a `finally` like construct using algebraic effects and handlers, that allows us to safely handle resources?

**Tags:** continuations, algebraic-effects

> **Comments:**
> **username_1**: If you have `catch` but not `finally`, you can always write a `catch` block that merely performs cleanup and re-raises the exception. Perhaps something similar could work with algebraic effects? The non-linear use of the continuation could be problematic, though.  
> **username_0**: Yes I am worried about the fact that with algebraic effect handlers you can call the continuation zero, one or more times.  
> **username_2**: There is a recent arxiv paper by Danel Ahman and Andrej Bauer: https://arxiv.org/abs/1910.11629 that describes "runners" which differ from handlers and have an interface that uses "finally" clauses. I'll just leave this as a comment since Andrej is a frequent user here and so is likely to give an answer.  

---

## 0 answers

