algaeff icon indicating copy to clipboard operation
algaeff copied to clipboard

Add error effect?

Open oberblastmeister opened this issue 1 year ago • 1 comments

It should have this signature

module type S = sig
  type error

  val throw : error -> 'a
  val catch : (unit -> 'a) -> ('a, error) result
end

oberblastmeister avatar Oct 01 '24 18:10 oberblastmeister

@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. :slightly_smiling_face:

favonia avatar Oct 01 '24 20:10 favonia