@@ -924,30 +924,43 @@ which means that the type of `twelve` is also inferred to be `Int`.
924
924
925
925
## Opaque Parameter Types
926
926
927
- XXX Outline:
928
-
929
- - You can write ` some ` as the type for a parameter
930
- to a function, initializer, or subscript.
931
- - In that usage, it's syntactic sugar for a generic.
932
- - You can't refer to the generic type -- because it has no name.
933
- - If you write ` some P ` more than once,
934
- they each refer to a different type.
927
+ In addition to writing ` some ` to return an opaque type,
928
+ you can also write ` some ` in the type for a parameter.
929
+ However, when you write ` some ` in a parameter type
930
+ that's just a shorter syntax for generics, not an opaque type.
931
+ For example,
932
+ both of the functions below are equivalent:
935
933
936
934
``` swift
937
- func drawTwice (_ shape : some Shape) -> String {
935
+ func drawTwiceSome (_ shape : some Shape) -> String {
938
936
let drawn = shape.draw ()
939
937
return drawn + " \n " + drawn
940
938
}
939
+
940
+ func drawTwiceGeneric <SomeShape : Shape >(_ shape : SomeShape) -> String { ... }
941
+ ```
942
+
943
+ The ` drawTwiceSome(_:) ` function
944
+ uses the type ` some Shape ` for its argument.
945
+ This creates a new, unnamed, generic type parameter for the function
946
+ with a constraint that requires the type to conform to the ` Shape ` protocol.
947
+ Because the generic type doesn't have a name,
948
+ you can't refer to that type elsewhere in the function.
949
+ The ` drawTwiceGeneric(_:) ` function
950
+ uses a generic type parameter named ` SomeShape ` ,
951
+ and explicitly includes the protocol conformance requirement.
952
+
953
+ XXX Every parameter's type is independent
954
+
955
+ ``` swift
941
956
func combine (shape s1 : some Shape, with s2 : some Shape) -> String {
942
957
return s1.draw () + " \n " + s2.draw ()
943
958
}
944
-
945
- // The same as:
946
- func drawTwice <SomeShape : Shape >(_ shape : SomeShape) -> String { ... }
947
959
func combine <S1 : Shape , S2 : Shape >(shape s1 : S1, with s2 : S2) -> String { ... }
948
960
```
949
961
950
-
962
+ If you need to multiple generic parameters that are all the same type,
963
+ use the usual generic syntax instead.
951
964
952
965
<!--
953
966
This source file is part of the Swift.org open source project
0 commit comments