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

Add error effect? #34

Open
oberblastmeister opened this issue Oct 1, 2024 · 1 comment
Open

Add error effect? #34

oberblastmeister opened this issue Oct 1, 2024 · 1 comment

Comments

@oberblastmeister
Copy link

It should have this signature

module type S = sig
  type error

  val throw : error -> 'a
  val catch : (unit -> 'a) -> ('a, error) result
end
@favonia
Copy link
Contributor

favonia commented Oct 1, 2024

@oberblastmeister Thanks for the suggestion. I think what you suggested is closer to exceptions, not effects (in the OCaml terminology), because throw never returns. Algebraic effects will/should return eventually, for otherwise we might incorrectly skip exception handlers on the stack. For example, the following code could be wrong if throw never returns:

let f = openFile "..." in
Fun.protect ~finally:closeFile $ throw "error"

The only way to guarantee the resumption of the continuation after calling throw is to unconditionally raise some exception, but then we can just use exceptions directly. That's why the library dose not provide the error effect. Please let me know if I missed something. 🙂

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