Skip to content
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

Generics terminology #447

Merged
merged 21 commits into from
May 10, 2021
Merged

Generics terminology #447

merged 21 commits into from
May 10, 2021

Conversation

josh11b
Copy link
Contributor

@josh11b josh11b commented Apr 10, 2021

To talk about generics as a programming language feature, you need a lot of
specialized terminology. We need to agree on the words we are using and their
meaning before we can meaningfully talk about the design of the feature itself.

There a number of problems a glossary solves:

  • Not everyone knows every term, so having a single place to look them up will
    improve the ease of understanding, ease of contributing, and accessibility
    of the project.
  • There may not be widespread agreement on the meaning of some terms. In
    particular, individual programming languages tend to assign very specific
    meanings to terms used within their ecosystem.
  • Some terms may be used in multiple ways, but we only use the term with one
    specific meaning.
  • Some terms are our invention and we need to introduce them.

@josh11b josh11b requested a review from a team April 10, 2021 01:26
@josh11b josh11b added WIP proposal A proposal labels Apr 10, 2021
@google-cla google-cla bot added the cla: yes PR meets CLA requirements according to bot. label Apr 10, 2021
@josh11b
Copy link
Contributor Author

josh11b commented Apr 12, 2021

Proposal links (add links as proposal evolves):

@josh11b josh11b requested a review from a team April 12, 2021 19:59
@josh11b josh11b requested a review from a team as a code owner April 12, 2021 19:59
@josh11b josh11b added proposal rfc Proposal with request-for-comment sent out and removed WIP labels Apr 12, 2021

This parameter broadens the scope of the language construct on an axis defined
by that parameter, effectively defining a family of functions (or whatever)
instead of a single one.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is better to consider only constructs with template parameters defining a family of functions. Since constructs with generic parameters support separate type checking and even separate compilation, they are better thought of as one entity. Generic parameters are much closer to regular (dynamic) parameters. Especially since Carbon aspires to model types as values, it is very interesting to compare the capabilities of generic parameters and dynamic parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is still a family of functions with respect to the function signature, right? Otherwise how would you characterize what expressive power you are gaining by adding the generics feature?

Copy link
Contributor

Choose a reason for hiding this comment

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

This might be splitting hairs, but since you are asking... Feel free to resolve without any changes.

A generic function does represent a potentially infinite set of non-generic function signatures. Until monomorphization (which happens after type checking) we don't know the exact set of signatures that the program instantiates. Furthermore, when we call a generic function from another generic function, we can't be working with the family interpretation of the generic callee, we must be considering it as one entity with a "forall T" constraint, in order to type check the call.

What I'm saying is that generic parameters are closer to regular dynamic parameters. As long as the generic or dynamic parameter passes type checking according to the function signature, the single function definition must be able to process them.

Similarly, non-generic functions must process any input values of the correct type, but I don't think one would usually describe a non-generic function as a family of values with respect to function's arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I talked to a few others and we settled on some new words that weaken the connection to "family of functions".

docs/design/generics/terminology.md Outdated Show resolved Hide resolved
docs/design/generics/terminology.md Show resolved Hide resolved
@josh11b josh11b requested a review from a team as a code owner April 16, 2021 17:03
docs/design/generics/terminology.md Outdated Show resolved Hide resolved
docs/design/generics/terminology.md Outdated Show resolved Hide resolved
docs/design/generics/terminology.md Outdated Show resolved Hide resolved
docs/design/generics/terminology.md Outdated Show resolved Hide resolved
docs/design/generics/terminology.md Outdated Show resolved Hide resolved
docs/design/generics/terminology.md Outdated Show resolved Hide resolved
docs/design/generics/terminology.md Outdated Show resolved Hide resolved
docs/design/generics/terminology.md Outdated Show resolved Hide resolved
docs/design/generics/terminology.md Outdated Show resolved Hide resolved
docs/design/generics/terminology.md Outdated Show resolved Hide resolved
Copy link
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good to me.

@gribozavr Can you take a pass over your comments and check to see if any represent blocking concerns?

@gribozavr
Copy link
Contributor

No blocking concerns!

@josh11b josh11b merged commit 9b16f95 into carbon-language:trunk May 10, 2021
@github-actions github-actions bot added proposal accepted Decision made, proposal accepted and removed proposal rfc Proposal with request-for-comment sent out labels May 10, 2021
@josh11b josh11b deleted the generics-terminology branch May 10, 2021 23:42
chandlerc pushed a commit that referenced this pull request Jun 28, 2022
To talk about generics as a programming language feature, you need a lot of
specialized terminology. We need to agree on the words we are using and their
meaning before we can meaningfully talk about the design of the feature itself.

There a number of problems a glossary solves:

Not everyone knows every term, so having a single place to look them up will
improve the ease of understanding, ease of contributing, and accessibility
of the project.
There may not be widespread agreement on the meaning of some terms. In
particular, individual programming languages tend to assign very specific
meanings to terms used within their ecosystem.
Some terms may be used in multiple ways, but we only use the term with one
specific meaning.
Some terms are our invention and we need to introduce them.


Co-authored-by: Richard Smith <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes PR meets CLA requirements according to bot. proposal accepted Decision made, proposal accepted proposal A proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants