-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
MPR#6709: document operators' associativity and precedence level #1167
Conversation
Document the associativity and precedence level of pervasives operators.
For completeness, I'd add the precedence of In all cases there should be a hyphen "Left-associative" and "Right-associative". I personally would say "at precedence level" or "with precedence |
Thanks for the remarks, I have added the missing hyphens and replaced "with precedence level" by "at precedence level". However, I have left a gap in the precedence levels corresponding to the |
Oh yes, I said 1/9 when I meant 9/9 before! This looks great, thanks - squashing and merging... |
I was criticizing the current way precedence levels are described in the context of #2097, so I'm moving the discussion here. I believe that "7/11" is not a very satisfying human-interface choice to describe the precedence of an operator. I am unable to tell what that means without looking at the manual, and the manual already gives me the precedence of the operator anyway, so the information as it is given is not very useful. The associativity is fine, because it is specified in terms that humans can understand. The problem is with the precedence level. Here are things that I think would be better than saying n/11:
|
I agree that using simple ordinal is not really satisfying. However, it has the advantage of being both local (at the operator level), (pointlessly) precise and does not require a lot of setup. More precisely, among your suggestion
Going on with you third suggestion, It might be easier to split the precedence table in subsections,
with a link to the table. |
Thanks for the reactivity! (And sorry about the somewhat negative tone of my previous comment...) I'm not sure about splitting the table. I like having a single place to get a global view of precedence, and note that user-defined operators need not follow the semantic category used by standard-library operators in the same syntactic category. (Maybe seeing a rendered version of your suggestion could improve my feeling, but I'm not asking you to do that unless you yourself believe we should split that way.) I like the idea of having a copy of the table within the standard-library documentation, so that we can easily (and robustly) hyperlink to it from the documentation. I like your proposed document for (%), except for the "arithmetic precedence group" that doesn't really talk to me. Note that knowing the relative precedence across semantic groups is also important in practice (for example, Thanks for providing a concrete example, it's easier to discuss with them. |
You were perfectly right to criticize the current documentation. Rather than splitting the table, I was thinking of something like
with Another option might be to add references to the 4-nearest neighbors:
which has the advantage of reducing the diameter of the induced graph to 3. |
I'm happy with the 4-nearest approach, although I can see how that might feel a bit cumbersome to contributors of new infix operators. Maybe making it slightly more work to add new infix operators is a feature... |
I'm not convinced by the nearest approach, the only think that is going to be ever clear is the actual table and I think reproducing it in the api docs and link to it from each operator would be the best. |
I was thinking of having both a link to the actual table and references to the neighboring precedence classes. Do you think that the neighboring classes are too noisy? |
Maybe speaking in terms of classes may help actually. The 4-nearest neighbours did however feel noisy. |
Mantis:6709:
This PR proposes to document the associativity and precedence level of the infix operators defined in the
Pervasives
module. This information is redundant with the description of operators in the reference manual. However, such description is neither directly referenced in thePervasives
module and probably nor always fresh in the mind of potential readers.I am also wondering if non-infix operators should be documented too, or if there are any natural name for the various precedence levels of infix operators.