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 functions related to type ('a, 'b) result #6995
Comments
Comment author: @c-cube I think functions that work on ('a, 'b) result are useful (and indeed most stdlib extensions/replacements will provide them), but I strongly dislike the addition of new infix operators. A module for result could be added, with named functions (map, flat_map, etc.) but please don't pollute Pervasives... |
Comment author: Cacophrene You may also consider that this was only a feature request, aka a suggestion that is made to be discussed, amended or even denied, but not at all an attempt to pollute the stdlib. Thanks for weighing your words. That said, I like the idea of a dedicated module. |
Comment author: @c-cube Sorry, I didn't mean to be rude. I'm all in favor of extending the stdlib if it's not in Pervasives. |
Comment author: Cacophrene OK, no worries. We agree on the usefulness of a dedicated module. |
Comment author: @alainfrisch This is a very reasonable request. Marking as Suspended, since no recent activity on it, but a PR is welcome! |
Comment author: Cacophrene Sorry for the silly question, but what is a PR? I would be very happy to contribute but I do not know how to proceed. Thanks for your time anyway. |
Comment author: @alainfrisch It's a Pull Request on github, where OCaml is now hosted. Some information about contributing: https://github.com/ocaml/ocaml/blob/trunk/CONTRIBUTING.md |
Comment author: Cacophrene OK thanks I will have a look. |
Original bug ID: 6995
Reporter: Cacophrene
Assigned to: @alainfrisch
Status: resolved (set by @alainfrisch on 2016-12-08T15:58:29Z)
Resolution: suspended
Priority: normal
Severity: feature
Version: 4.02.3
Category: standard library
Monitored by: @gasche @diml
Bug description
It would be very nice to have some functions to help using type ('a, 'b) result smoothly, such as eval, map and fix below :
let eval f x = try Ok (f x) with e -> Error e
(* map function *)
let ( |? ) res f =
match res with
| Ok x -> eval f x
| Error e -> Error e
(* fix function *)
let ( |! ) res f =
match res with
| Error e -> eval f e
| ok -> ok
It would then be very easy to use the result type as input and output values, with possibility to fix errors when needed.
The text was updated successfully, but these errors were encountered: