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 functions related to type ('a, 'b) result #6995

Closed
vicuna opened this issue Sep 18, 2015 · 8 comments
Closed

Add functions related to type ('a, 'b) result #6995

vicuna opened this issue Sep 18, 2015 · 8 comments

Comments

@vicuna
Copy link

vicuna commented Sep 18, 2015

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.

@vicuna
Copy link
Author

vicuna commented Sep 19, 2015

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...

@vicuna
Copy link
Author

vicuna commented Sep 19, 2015

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.

@vicuna
Copy link
Author

vicuna commented Sep 19, 2015

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.

@vicuna
Copy link
Author

vicuna commented Sep 19, 2015

Comment author: Cacophrene

OK, no worries. We agree on the usefulness of a dedicated module.

@vicuna
Copy link
Author

vicuna commented Dec 8, 2016

Comment author: @alainfrisch

This is a very reasonable request. Marking as Suspended, since no recent activity on it, but a PR is welcome!

@vicuna vicuna closed this as completed Dec 8, 2016
@vicuna
Copy link
Author

vicuna commented Dec 8, 2016

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.

@vicuna
Copy link
Author

vicuna commented Dec 8, 2016

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

@vicuna
Copy link
Author

vicuna commented Dec 8, 2016

Comment author: Cacophrene

OK thanks I will have a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants