From: Robert Griesemer
-A type parameter is an (unqualified) type name declared in the -type parameter list of a -function declaration or -type definition; or in the receiver specification -of a method declaration that is associated -with a generic type. -A type parameter acts as a place holder for an (as of yet) unknown type in the declaration; -the type parameter is replaced with a type argument upon -instantiation of the generic function or type. -
- --The properties of a type parameter are determined by its -type constraint. -
-By definition, a core type is never a defined type, -type parameter, or +type parameter, or interface type.
@@ -2047,7 +2028,7 @@ toT
.
A constant x
is representable
by a value of type T
,
-where T
is not a type parameter,
+where T
is not a type parameter,
if one of the following conditions applies:
-A type parameter list declares the type parameters -in a generic function or type declaration. +A type parameter list declares the type parameters of a generic function or type declaration. The type parameter list looks like an ordinary function parameter list except that the type parameter names must all be present and the list is enclosed in square brackets rather than parentheses. @@ -2642,9 +2622,11 @@ TypeParamDecl = IdentifierList TypeConstraint .
-Each identifier declares a type parameter. All non-blank names in the list must be unique. -Each type parameter is a new and different named type. +Each name declares a type parameter, which is a new and different named type +that acts as a place holder for an (as of yet) unknown type in the declaration. +The type parameter is replaced with a type argument upon +instantiation of the generic function or type.
@@ -2686,6 +2668,12 @@ type T[P interface{*C}] ⦠type T[P *C,] â¦+
+Type parameters may also be declared by the receiver specification +of a method declaration associated +with a generic type. +
+
@@ -3829,7 +3817,7 @@ For a
of map type M
:
-For a
of type parameter type P
:
+For a
of type parameter type P
:
P
must have specific types.
For an expression x
of interface type,
-but not a type parameter, and a type T
,
+but not a type parameter, and a type T
,
the primary expression
-Excluding shifts, if the operand type is a type parameter,
+Excluding shifts, if the operand type is a type parameter,
it must have specific types, and the operator must
apply to each specific type.
The operands are represented as values of the type argument that the type parameter
@@ -5295,7 +5283,7 @@ as for non-constant x
.
-Converting a constant to a type that is not a type parameter +Converting a constant to a type that is not a type parameter yields a typed constant.
@@ -5350,7 +5338,7 @@ in any of these cases:x
's type and T
are not
- type parameters but have
+ type parameters but have
identical underlying types.
T
against the dynamic type of the
expression x
. As with type assertions, x
must be of
interface type, but not a
-type parameter, and each non-interface type
+type parameter, and each non-interface type
T
listed in a case must implement the type of x
.
The types listed in the cases of a type switch must all be
different.
@@ -6351,7 +6339,7 @@ if v == nil {
-A type parameter or a generic type +A type parameter or a generic type may be used as a type in a case. If upon instantiation that type turns out to duplicate another entry in the switch, the first matching case is chosen.
@@ -7092,7 +7080,7 @@ cap(s) [n]T, *[n]T array length (== n)
-If the argument type is a type parameter P
,
+If the argument type is a type parameter P
,
P
must have specific types, and
the call len(e)
(or cap(e)
respectively) must be valid for
each specific type of P
.
@@ -7316,7 +7304,7 @@ delete(m, k) // remove element m[k] from map m
-If the type of m
is a type parameter,
+If the type of m
is a type parameter,
it must have specific types, all specific types
must be maps, and they must all have identical key types.