File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -921,6 +921,34 @@ which means that the type of `twelve` is also inferred to be `Int`.
921
921
}
922
922
-->
923
923
924
+
925
+ ## Opaque Parameter Types
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.
935
+
936
+ ``` swift
937
+ func drawTwice (_ shape : some Shape) -> String {
938
+ let drawn = shape.draw ()
939
+ return drawn + " \n " + drawn
940
+ }
941
+ func combine (shape s1 : some Shape, with s2 : some Shape) -> String {
942
+ return s1.draw () + " \n " + s2.draw ()
943
+ }
944
+
945
+ // The same as:
946
+ func drawTwice <SomeShape : Shape >(_ shape : SomeShape) -> String { ... }
947
+ func combine <S1 : Shape , S2 : Shape >(shape s1 : S1, with s2 : S2) -> String { ... }
948
+ ```
949
+
950
+
951
+
924
952
<!--
925
953
This source file is part of the Swift.org open source project
926
954
You can’t perform that action at this time.
0 commit comments