Add Option.product and Option.Syntax#13916
Conversation
|
There are two sensible interpretations of |
dbuenzli
left a comment
There was a problem hiding this comment.
Looks good to me. Just left a few non essential comments.
|
It's not clear to me whether @gasche's comment is an opposition to add |
|
It's clear to me that there is a problem here, but I'm not sure how to solve it. The simplest way would be to not provide The other approach I see is to define # let+ x = [1; 2] and+ y = [10; 20] in x+y;;
- : int list = [11; 22]
# let+ x = [1; 2] and+ y = [10; 20; 30] in x+y;;
Exception: Invalid_argument "List.combine".
# let+ x = [1; 2] and* y = [10; 20; 30] in x+y;;
- : int list = [11; 21; 31; 12; 22; 32]I am not sure whether the same considerations should apply to |
|
(I wonder if @lpw25 has an opinion about this. Should |
|
I understand the value of Do you have an example where these are used in a useful manner in the wild? |
According to what I read here the zipping product is a notorious example of an applicative functor that is not a monad. Now since all monads are applicative functors, as a matter of convention I would find it weird that |
Incidentally, this same point was also made in #2170 (comment):
|
|
Shall we try to move forward here? Two options:
@gasche: do you agree with the point made in #2170 (comment) that the applicative and monadic products should be the same for |
|
I'm not fond of having Note: re-reading the discussion of #2170, I realize that Leo proposed to have I might propose a |
|
Personally I would rather be in favour of just adding |
|
I believe that we all agree that |
|
My point is rather not adding stuff that ends up being mostly unused. |
7a5924e to
eb0616d
Compare
|
OK, let's stick to |
eb0616d to
378eaf8
Compare
|
@gasche Friendly ping: are you willing to approve the PR in its current state? |
gasche
left a comment
There was a problem hiding this comment.
I approve with the reduced scope, but have suggestions on the proposed mli documentation which I find too terse for people who don't already know binding operators.
| module Syntax : sig | ||
|
|
||
| val ( let* ) : 'a option -> ('a -> 'b option) -> 'b option | ||
| (** [( let* )] is {!Option.bind}. *) |
There was a problem hiding this comment.
I would prefer if API docs for binding operators would show the syntax in use, or at least if they would refer explicitly to a chapter in the manual that explains this. Currently the documentation is obscure if you don't already know binding operators, and the syntax is not self-discoverable.
There was a problem hiding this comment.
I added a pointer to the relevant manual section. I did the same for Result.Syntax. Examples would be nice, but it will probably be a more sizeable task and better taken up on its own. Please yell if you are not happy with the current state of the PR. Otherwise I am planning to merge by end of day.
7181fde to
5056346
Compare
|
This needs a second approval from a maintainer. Would @Octachron, @dra27, @OlivierNicole possibly have an opinion? (Note: Daniel formally approved the PR, so one option is to green-approve on his behalf.) |
5056346 to
1bbc9c5
Compare
Thanks for the approval, will merge once CI passes. |
EDIT: contrary to what is written below, following discussion, this PR only adds
Option.productandOption.Syntax.As a follow-up to #13696, this PR adds a
Syntaxsubmodule toOption,ListandSeqcontaining binding operators for these modules. Along the way, it also addsOption.productandList.product.The addition of the
Syntaxsubmodules was discussed and approved in principle during the last dev meeting.