4 ms·
>Doesn't this mean you could implement a generic tree type if you fix the underlying data structure to be an array/map? Nope. There are only a few functions th
by edmccard 10y ago
>Doesn't this mean you could implement a generic tree type if you fix the underlying data structure to be an array/map?
Nope. There are only a few functions that accept type parameters, and they must be called with concrete types, and they only work with certain aggregate types. For example, "make" can only be used to create slices, maps or channels, so you could create a slice of 10 bytes with "make([]bytes, 10)" but you cannot write "make(T)" or even "make([]T, 10)" where T is a type variable, and you also can't do "make(Tree)" where Tree is, e.g, some struct type.
- woah 10y agoI think it's better to not even think of them as "generic functions". Think of them as language keywords which happen to have the syntax of functions.