This proposal is to add generic native types (GNTs) to Go: generic versions of each of the native builtin types (e.g., map
= generic map, slice
= generic slice, number
= generic number, float
= generic float, signed
= generic signed integer, unsigned
= generic unsigned integer, etc).
GNTs support a substantial proportion of generic programming functionality, without adding any new syntax to the language: generic code looks identical to regular Go code, except for the use of these generic type names, and a few extra functions that access the type parameters of container objects such as maps and slices (e.g., elem(x)
is the type of the elment in a slice or map; key(m)
is the type of the key of a map; field(s, fieldName)
is the type of the given named field in a struct
; return(f)
is the type of return value from function, and type(x)
is the type of a generic var, e.g., for use in return signature).
The generic struct
is the most challenging case, because of its unlimited number of t