-
Notifications
You must be signed in to change notification settings - Fork 168
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 more existentials documentation #340
base: main
Are you sure you want to change the base?
Conversation
print("The full name is \(fullyNamed.fullName)") | ||
} | ||
|
||
printFullName(ncc1701) |
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.
ncc1701
is defined on line 233
An existential can also creating by writing `any` before a protocol composition type (see <doc:Protocols#Protocol-Composition>). This creates a box which holds a structure, class or enum that conforms to all the protocols listed. | ||
|
||
``` | ||
protocol Named { |
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.
this protocol is also defined in line 1629 of the "Protocols" chapter
Thanks for writing this up as a pull request, and in particular thanks for taking the time to include the cross references between running code listings. I'll be out of the office next week for the Thanksgiving holiday, and will continue working with you on these changes when I get back. A few initial notes:
|
Thanks for the review!
Yes, I was trying to look up what the existentials any syntax supports (i.e. exactly what is legal to put in
Sure, I can revert this, but it seems strange to me that the Protocols chapter (which comes before the Generics chapter) talks about opaque types. |
@@ -1604,9 +1608,9 @@ that tries to adopt `SomeClassOnlyProtocol`. | |||
## Protocol Composition | |||
|
|||
It can be useful to require a type to conform to multiple protocols at the same time. | |||
You can combine multiple protocols into a single requirement | |||
You can combine multiple protocols into a single *protocol composition 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.
The language reference calls this a "protocol composition type", but I think the compiler warnings call this a "protocol-constrained type" 🤔
This PR contains a few changes to add more documentation around existentials. Note that the "Protocols" chapter comes before the "OpaqueTypes" chapter.
Protocols as Types
with other examples of using protocols as typesProtocol Composition Type
is the named used by the Language Reference.Protocol Composition
for this. In my mind, this is a short form.