-
Notifications
You must be signed in to change notification settings - Fork 12
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
Does it make sense to include support for try
?
#8
Comments
I don't think so. Error handling semantics differ a lot between different monads, and I suspect this would just lead to surprising and hard to debug results. |
Fair enough. Libraries can provide their own handlers that thread through error handling partially recreating the behavior of exception handling. |
@yminsky @lpw25 I've been giving this a lot of thought because of the linked Reason issue. Would it make sense to optionally include a module type MONAD_ERROR = sig
type e
val catchError : 'a t -> f:(e -> 'a t) -> 'a t
val throwError : e -> 'a t
end
I don't think its shortcomings apply to OCaml. Tl;dr the signatures of I'm not implying
If some monad needs that behavior it can still implement it by catching inside each method ( I'm not aware of any precedent (Haskell, Scala, F#, PureScript, etc.) for sugaring let%bind ctx = get_context
let%bind cxn = let%try
connect_to_db ctx
with
| _ -> connect_to_backup ctx
let%bind stats = get_stats cxn Note the signatures of val bind : 'a t -> f:('a -> 'b t) -> 'b t
val catchError : 'a t -> f:( e -> 'a t) -> 'a t Their symmetry is intentional. Consider val bind : 'a exn result -> f:('a -> 'b exn result) -> 'b exn result
val catchError : 'a exn result -> f:(exn -> 'a exn result) -> 'a exn result
(* from *)
let%try M with P -> E
(* to *)
catch M ~f:(function P -> E) |
I was comparing ppx_let with lwt's ppx extension and I was curious if it makes sense for
ppx_let
to include support fortry
, where a module that definesbind
andmap
are also able to support transforms for handling exceptions.The text was updated successfully, but these errors were encountered: