Add Result.product and Result.Syntax#13696
Conversation
cf385aa to
774ada7
Compare
|
It seems that the additions changed something and made some lambda code tests fail. I blindly promoted them in e7f3914. I didn't fully understand the tests but I guess some |
|
I'd much prefer so that (I'd also add an alias |
|
@wikku I don't think there's much value in making that more general. The proposed functions just make it convenient to interoperate with other idioms that are part of the stdlib. They are easy to read, easy to write and consistent with what already exists. |
|
I disagree that
I am not opposed to introducing functions that help with the pattern of using exceptions internally and |
The prime is precisely unimportant. The idiom We have I have in the past used various other names for that (e.g. the ill named
I don't think these additions preclude adding more general things if people want to. However translating I'd just like to add that what I'm adding here is based on quite a lot of design rounds on this including in |
|
For the record, I rather like Thinking out loud: having this function would possibly suggest Regarding the other questions/suggestions of @dbuenzli:
|
Personally I'm not sure I would be using it, so I won't be the one adding it now. I would however quite disagree with the name itself. I'd really prefer if we keep
I'd rather not :–)
What are the difficulties ? Six years later it seems to be a rather low risk addition to me. As I mentioned, the current bindings operators and their use for the error monad are not going to go. If you want to add a module that introduces the hypothethical named binding operators in the future you could add them in |
|
Would you consider renaming |
|
@dbuenzli maybe you should consider splitting the PR in three, because I think that it's easier (at least for me) to make progress on some points than others. |
e7f3914 to
7b47b72
Compare
|
The split has been done. Please continue the discussion about:
I don't know, |
|
I don't want bikesheeding because I think the name |
|
Well if no agreement can be found I'm also willing to simply not expose it, what I want in is |
|
For what it's worth, I think the name |
It is also used by CCResult. Additionally, not everyone may associate |
What kind of confusion ? Personally I'd find Again the added term here is to satisfy an But if people prefer that I remove it, so be it. Footnotes
|
My point pertains to the fact that not everybody would make the connection between the name
The suggestion of
The standard library should minimize the need for developers to "learn something new". Functional programming has long faced criticism for its reliance on terminology that references category theory / abstract algebra, and we should avoid reinforcing this perception where possible.
The Overall, in my opinion, |
Personally I'd rather expect
Because having the right name allows people outside from the standard library to define an APPLICATIVE over If people want to follow up with |
|
OK, at this point I feel the discussion is diverging. Discussions about which name is best are inherently subjective and as such there can be no objective "argument" that will win the day. Personally I have stopped worrying long ago about such things and just try to find names which enjoy some rough consensus and do not aspire to more than that. (And I believe this attitude has saved me quite a lot of time that could have been wasted in pointless discussions.) With this in mind, I would suggest to stop discussing the naming of On this question, @gasche wondered about the interactions with the named binding operators of #13325 (see also #12015). Personally I see the relation between named binding operator ( |
We are in agreement but I still think we should be forward looking here and think about a scheme were both named binding operators and unnamed ones can cohabit ergonomically if they become a reality. I don't think having both defined in the My proposal which was perhaps a bit lost above is to generally have the unnamed ones in: and the named ones in: Perhaps this can make people who believe in named binding operators worry a little bit less about what is being introduced here. |
7b47b72 to
d600006
Compare
|
This is also part of the plan of getting rid of my tiny and annoying to carry It has been two months now and I think a decision should be taken on that one, either we finally get that six years old proposal in or I'll simply close this. Personally I can confidently say that the For appeasing the believers in named binding operators, a suggestion was made for a convention to introduce them if they end up being added to language and this PR is accepted. |
|
+1, I'm very looking forward to seeing this sugar in the upcoming OCaml release. |
This was discussed in today's dev meeting. There was consensus around adding a submodule with the usual monadic operators A PR consisting exclusively of the addition of these modules would be welcome, but expect some bikeshedding around the choice of the name of the submodule. Thanks! |
|
Personally I'm not interested in adding modules for The work is done here, can't we have the discussion about the name here and make this the PR for I don't think we need a big bang PR. People can gradually add monads to the other modules later if they find it useful. |
|
So, to challenge
Hence Pay attention! Below, some of the usual operators (e.g. arithmetic), or usual bits of syntax |
Sure, we can do that. Do you mind removing To recapitulate, the question is: what should we call the submodule of The current proposal for the name is Other potential names for this submodule: cc some core devs who may have an opinion @gasche @chambart @lthls @yallop |
d600006 to
18ea176
Compare
|
Done.
A counter to these names can be found here. |
18ea176 to
3a090e4
Compare
|
In the maintainer meeting, we approved in principle the idea of |
|
@gasche: according to my notes, there was some indecision about the name, but do I take it from your comment that |
I think Another alternative could be |
That's good to hear. At this point I am willing to go with the choice of the author, unless there's a clear argument or wide consensus against it. |
My arguments against are similar to those exposed there against Moreover, it would then become a reader's expectation that Personally I don't think having fine grained names for syntax rebinding is useful. It feels needlessly bureaucratic to me, I rather have a good, all round, generic term for that. |
|
For information, I will wait until end of day on Monday to give time for people to participate. If no substative arguments have come up by then, I am planning to merge the PR. |
3a090e4 to
5e84b23
Compare
|
I wanted to ask if there is a pre-established justification for using |
|
Just so that we go to the bottom of everything :-) I think that both |
|
Merged. Thank you everyone for your participation. |
|
Wow... |
This PR adds
Result.Syntaxwith the binding operators forresultvalues.Before it also added
Result.{get_ok',error_to_failure}, now living in Add Result.{get_ok',error_to_failure} #13720Result.retract, now living in Add Result.retract #13721Binding operators
This is a partial implementation of what has been proposed by @lpw25 in #2170 six years ago. However the
Syntaxmodule proposed here provides only binding operators, there is noreturn. I find it clearer to use the dedicated constructorOkorResult.okdirectly and I think it's better not to pollute our crowded scopes with unqualified identifiers.It is something that I use in almost all of my source files and programs.
Some people would like the named binding operator of #13325 to settle down before deciding this (see this discussion). However no one ever seemed to address this question and more than one person points out that they end up using at most one monad most of time in a given context (which hints at an answer to the question).
However when the latter is true named binding operators become both extremely noisy and a waste of your horizontal space. Personally I'm extremely unlikely to use them for my pervasive use of the error monad. Hence the proposal whose usage will, I suspect, outlive any named binding operator introduction, if it ever happens.