Skip to content

Commit a70eff5

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

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pep-0695.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,31 @@ 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.
1192+
1193+
Go does not support generic type aliases.
1194+
1195+
.. code-block:: go
1196+
1197+
// Generic type without a bound
1198+
type TypeA[T any] struct {
1199+
t T
1200+
}
1201+
1202+
// Type parameter with upper bound
1203+
type TypeB[T SomeType1] struct { }
1204+
1205+
// Generic function
1206+
func func1[T any]() { }
11821207
11831208
11841209
Summary
@@ -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)