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

Add discussion of 'some' on parameter types [SE-0341] #350

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

amartini51
Copy link
Member

Fixes: rdar://143326925

- Start with the generic syntax, since that's what readers have seen in
  previous chapters already.
- Walk through an example of using 'some' more than once.
- Match func/subscript/init order in prose to chapter ordering.
```

The `drawTwiceGeneric(_:)` function
uses a generic type parameter named `SomeShape`,
Copy link
Contributor

Choose a reason for hiding this comment

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

s/uses/declares/ ?


The `drawTwiceGeneric(_:)` function
uses a generic type parameter named `SomeShape`,
and explicitly includes the protocol conformance requirement.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/includes/states/ ?

Also do we call them "requirements" or "constraints" here? You also use "constraint" below

Copy link
Member Author

Choose a reason for hiding this comment

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

Reworded & changed. The chapter on generics also calls these "constraints".

in this case, one triangle and one trapezoid.
If you need to write a function
that has multiple generic parameters
and constrain them to be are all the same type,
Copy link
Contributor

Choose a reason for hiding this comment

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

s/are // ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

If you need to write a function
that has multiple generic parameters
and constrain them to be are all the same type,
use the usual generic syntax instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

Clarify "usual syntax": s/usual generic syntax/syntax for a named generic type parameter/ ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed. Good point that both of these syntaxes can be considered "usual" now & in the future.

to indicate that they're a placeholder for a *type*, not a value.

> Note:
> If you don't need to name a type parameter or give it any constraints,
Copy link
Contributor

Choose a reason for hiding this comment

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

More precisely, opaque parameters can be subject to conformance and superclass requirements -- that's the part that follows the some keyword. But they can't be subject to same-type requirements

Copy link
Member Author

Choose a reason for hiding this comment

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

Reworded

## Opaque Parameter Types

In addition to writing `some` to return an opaque type,
you can also write `some` in the type for a parameter
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe that's a bigger change than what you're after here, but I would introduce some parameters first, before some returns maybe.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can revisit, but I think I'd like to keep this structure. The some syntax serves two purposes: as a lightweight syntax for generics — generics have their own discussion elsewhere — and as opaque return types. So the new concept that some brings is opaque types.

Copy link
Contributor

@chuckdude chuckdude left a comment

Choose a reason for hiding this comment

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

Approved with a single edit (removal of a comma).

Edits from <rdar://145499286>.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants