Skip to content

Commit

Permalink
PEP 659: Add Go
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Jul 24, 2022
1 parent 9fb3d64 commit d1b596f
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion pep-0695.rst
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ Java provides no way to specify a default type argument.
// Generic method
public <S extends Number> void method1(S value) { }
// Use site variance
public void method1(ClassA<? super Integer> value) { }
}
Expand Down Expand Up @@ -1123,7 +1124,12 @@ Kotlin provides no way to specify a default type argument.
class ClassC<in S, out T>
// Generic function
fun <T> func1(): T { }
fun <T> func1(): T {
// Use site variance
val covariantA: ClassA<out Number>
val contravariantA: ClassA<in Number>
}
// Generic type alias
typealias TypeAliasFoo<T> = ClassA<T>
Expand Down Expand Up @@ -1179,6 +1185,31 @@ Dart provides no way to specify a default type argument.
// Generic type alias
typedef TypeDefFoo<T> = ClassA<T>;
Go
--

Go uses square brackets to declare type parameters and for specialization.
The upper bound of a type is specified after the name of the parameter, and
must always be specified. The keyword ``any`` is used for an unbound type parameter.

Go doesn't support variance; all type parameters are invariant.

Go provides no way to specify a default type argument.

Go does not support generic type aliases.

.. code-block:: go
// Generic type without a bound
type TypeA[T any] struct {
t T
}
// Type parameter with upper bound
type TypeB[T SomeType1] struct { }
// Generic function
func func1[T any]() { }
Summary
Expand Down Expand Up @@ -1214,6 +1245,8 @@ Summary
| Dart | <> | extends | | | decl | in, out, |
| | | | | | | inout |
+------------+----------+---------+--------+----------+-----------+-----------+
| Go | [] | T X | | | n/a | n/a |
+------------+----------+---------+--------+----------+-----------+-----------+
| Python | [] | T: X | | | decl | inferred |
| (proposed) | | | | | | |
+------------+----------+---------+--------+----------+-----------+-----------+
Expand Down

0 comments on commit d1b596f

Please sign in to comment.