-
Notifications
You must be signed in to change notification settings - Fork 173
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
base: main
Are you sure you want to change the base?
Conversation
- 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`, |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/are // ?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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/ ?
There was a problem hiding this comment.
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.
TSPL.docc/LanguageGuide/Generics.md
Outdated
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Co-authored-by: Slava Pestov <[email protected]>
There was a problem hiding this 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>.
Fixes: rdar://143326925