Skip to content

Commit 11d3166

Browse files
committed
PEP 659: Add Go
1 parent 9fb3d64 commit 11d3166

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pep-0695.rst

+27
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,32 @@ Dart provides no way to specify a default type argument.
11791179
// Generic type alias
11801180
typedef TypeDefFoo<T> = ClassA<T>;
11811181
1182+
Go
1183+
--
1184+
1185+
Go uses square brackets to declare type parameters and for specialization.
1186+
The upper bound of a type is specified after the name of the parameter, and
1187+
must always be specified. The keyword ``any`` is used for an unbound type parameter.
1188+
1189+
Go doesn't support variance; all type parameters are invariant.
1190+
1191+
Go provides no way to specify a default type argument.
11821192

1193+
.. code-block:: go
1194+
1195+
// Generic type without a bound
1196+
type TypeA[T any] struct {
1197+
t T
1198+
}
1199+
1200+
// Type parameter with upper bound
1201+
type TypeB[T SomeType1] struct { }
1202+
1203+
// Generic function
1204+
func func1[T any]() { }
1205+
1206+
// Generic type alias
1207+
type TypeAlias[T any] TypeA[T]
11831208
11841209
Summary
11851210
-------
@@ -1214,6 +1239,8 @@ Summary
12141239
| Dart | <> | extends | | | decl | in, out, |
12151240
| | | | | | | inout |
12161241
+------------+----------+---------+--------+----------+-----------+-----------+
1242+
| Go | [] | T X | | | n/a | n/a |
1243+
+------------+----------+---------+--------+----------+-----------+-----------+
12171244
| Python | [] | T: X | | | decl | inferred |
12181245
| (proposed) | | | | | | |
12191246
+------------+----------+---------+--------+----------+-----------+-----------+

0 commit comments

Comments
 (0)