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 Aug 28, 2022
1 parent a7b84dd commit 2fbe588
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 @@ -1133,7 +1134,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 @@ -1189,6 +1195,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 @@ -1224,6 +1255,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 2fbe588

Please sign in to comment.