Skip to content

Named binding operators, take two#13325

Open
gasche wants to merge 2 commits intoocaml:trunkfrom
gasche:named-binding-operators
Open

Named binding operators, take two#13325
gasche wants to merge 2 commits intoocaml:trunkfrom
gasche:named-binding-operators

Conversation

@gasche
Copy link
Copy Markdown
Member

@gasche gasche commented Jul 20, 2024

This PR proposes to extend the current "symbolic" binding operators (( let+ ), ( let* )) with "named" binding operators (( let/map ), ( let/bind )).

This PR is a reboot of @EduardoRFS's #10979, with a slightly different syntax (the initial proposal was let.map, let.bind proposed by @lpw25 in the broader discussion in #12015. There seems to be a broad consensus (in #10979, #12015 and in #2170) that the current "symbol operators" approach is too limited in terms of readability when mixing several different kinds of bindings, and that named operators would result in more readable code.

The current version does not support "mixed" symbol+names operators such as let/map+ or let/list*, or maybe let+/list and let+/option. The plan is to eventually support a qualified form Option.let/map instead, but I would like to further discuss the syntax for this in #12015 so it is not in the first iteration of the present PR.

@gasche
Copy link
Copy Markdown
Member Author

gasche commented Jul 20, 2024

See #12015 (comment) for a new discussion item on qualified binding operators (some of Option.let/map, let/Option.map, Option.let+, etc.). I believe that the proposed feature has value even in absence of qualification: it can be used with local opens as we do for binding operators today, and the readability benefits still apply.

(I would still like to think about qualification because I think that Option.let/map or let/Option.map are nicer way to combine several modules than say mixing let/option and let/list.)

@lpw25
Copy link
Copy Markdown
Contributor

lpw25 commented Jul 22, 2024

The plan is to eventually support a qualified form Option.let/map

My vote would be for let/Option.map even if it expands to Option.(let/map). I think that it is easier to read and it encourages people to define map and let/map as (semantically) the same function in a monad or applicative. That way you can read let/Option.map as essentially doing Option.map, just using a different identifier because e.g. you might want to label the function argument on your actual Option.map.

An alternative would be something like let/Option/map, which isn't too bad.

@gasche
Copy link
Copy Markdown
Member Author

gasche commented Jul 22, 2024

In any case there are conflicts with the Option.let/map syntax, as discussed in the discussion in #12015 (comment) . (I would rather focus in this PR on the discussion of the feature without module qualification, its desirability of course and its implementation.)

@gasche
Copy link
Copy Markdown
Member Author

gasche commented Oct 28, 2024

We discussed this PR at the maintainer meeting today. People are generally in favor, but they would like to see support for the qualified syntax, let/Option.map (which desugars into Option.( let/map ) before making a final decision on the feature.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants