You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/GenericsManifesto.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -369,7 +369,7 @@ func apply<... Args, Result>(fn: (Args...) -> Result, // function taking some
369
369
370
370
### Extensions of structural types
371
371
372
-
Currently, only nominal types (classes, structs, enums, protocols) can be extended. One could imagine extending structural types—particularly tuple types—to allow them to, e.g., conform to protocols. For example, pulling together variadic generics, parameterized extensions, and conditional conformances, one could express "a tuple type is `Equatable` if all of its element types are `Equatable`":
372
+
Currently, only nominal types (classes, structs, enums, protocols) can be extended. One could imagine extending structural types--particularly tuple types--to allow them to, e.g., conform to protocols. For example, pulling together variadic generics, parameterized extensions, and conditional conformances, one could express "a tuple type is `Equatable` if all of its element types are `Equatable`":
373
373
374
374
```Swift
375
375
extension<...Elements:Equatable> (Elements...) :Equatable { // extending the tuple type "(Elements...)" to be Equatable
@@ -450,7 +450,7 @@ The `where` clause of generic functions comes very early in the declaration, alt
One could move the `where` clause to the end of the signature, so that the most important parts—name, generic parameter, parameters, result type—precede it:
453
+
One could move the `where` clause to the end of the signature, so that the most important parts--name, generic parameter, parameters, result type--precede it:
454
454
455
455
```Swift
456
456
funccontainsAll<S: Sequence>(elements: S) ->Bool
@@ -636,7 +636,7 @@ func foo(value: Any) {
636
636
foo(X())
637
637
```
638
638
639
-
Under what circumstances should it print "P"? If `foo()` is defined within the same module as the conformance of `X` to `P`? If the call is defined within the same module as the conformance of `X` to `P`?Never? Either of the first two answers requires significant complications in the dynamic casting infrastructure to take into account the module in which a particular dynamic cast occurred (the first option) or where an existential was formed (the second option), while the third answer breaks the link between the static and dynamic type systems—none of which is an acceptable result.
639
+
Under what circumstances should it print "P"? If `foo()` is defined within the same module as the conformance of `X` to `P`? If the call is defined within the same module as the conformance of `X` to `P`?Never? Either of the first two answers requires significant complications in the dynamic casting infrastructure to take into account the module in which a particular dynamic cast occurred (the first option) or where an existential was formed (the second option), while the third answer breaks the link between the static and dynamic type systems--none of which is an acceptable result.
640
640
641
641
### Conditional conformances via protocol extensions
0 commit comments