Contracts — Draft Design presents a draft proposal for adding generic types and functions to the Go programming language, using contracts to specify the behavior required of type parameters.
This document discusses two topics.
First, suppose generic types and functions are added to Go as in the contracts proposal, but without contracts. When a generic function f
has a type parameter T
, the only operations f
can perform on values of type T
are the operations that are available on all types. Is there a reasonable way to write generic code in these circumstances, with no other additions to the language? The answer seems to be
- Yes, this is quite doable.
- And it works well with both built-in and user-defined types.