Skip to content

explain the syntax change for variance (by #13820)#14126

Merged
garrigue merged 5 commits into
ocaml:trunkfrom
COCTI:doc_bivariance
Sep 11, 2025
Merged

explain the syntax change for variance (by #13820)#14126
garrigue merged 5 commits into
ocaml:trunkfrom
COCTI:doc_bivariance

Conversation

@t6s

@t6s t6s commented Jul 3, 2025

Copy link
Copy Markdown
Contributor

#13820 introduced the bivariance indicators (+-, -+) in the syntax.
This PR documents them.

@t6s

t6s commented Jul 3, 2025

Copy link
Copy Markdown
Contributor Author

What do you think should be added? @Octachron

@kit-ty-kate

Copy link
Copy Markdown
Member

is there a definition anywhere in the manual on what bivariance means? (and/or maybe some example?)

Comment thread manual/src/refman/typedecl.etex Outdated
"+", "-", "+-", or "-+" to indicate that the type constructor has a specific
variance with respect this parameter.
A parameter with "+" is covariant, "-" contravariant,
and "+-" (or "-+") bivariant.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can inline the definition of bivariant here:
A parameter prefixed with "+" is covariant, one prefixed with "-" is contravariant.
A parameter can be both covariant and contravariant, also known as bivariant, with either
a "+-" or "-+" prefix.

@Octachron

Octachron commented Aug 5, 2025

Copy link
Copy Markdown
Member

@t6s, if you don't have the time currently, would you mind if I were to take care of updating the manual?

@t6s

t6s commented Aug 5, 2025

Copy link
Copy Markdown
Contributor Author

@Octachron Thank you for the reminder, and sorry for leaving this issue for a long time. I have been about to come back to this issue around Aug 15. If it needs to be hurried, please take it over.

Comment thread manual/src/refman/typedecl.etex Outdated
'+'
| '-'
| '+-'
| '-+'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be vertically aligned with the - case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, they are TAB characters. I will replace them by spaces in the next commit.

@Octachron Octachron left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current explanation looks good to me. (Note that we are missing the description in the man pages but I propose to update them in a subsequent PR).

@t6s t6s marked this pull request as ready for review September 9, 2025 06:17
Comment thread manual/src/refman/typedecl.etex Outdated
variance information is used to decide subtyping relations when
The type variables appearing as type parameters can optionally be prefixed by
"+", "-", "+-", or "-+" to indicate that the type constructor has a specific
variance with respect this parameter.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"with respect this ..." ⇒ "with respect to this"

@garrigue garrigue merged commit 5364370 into ocaml:trunk Sep 11, 2025
33 checks passed
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.

5 participants