I think your example is not relevant, as it clearly intend to change the input type,
the goal is to preserve it, while still working with its value.
interface{} value type destroys the input type information,
so you might have the opposite value type,
a type that preserves.
A type that let you write,
func, please, return the type i got.
I did not mention templating, code generate / whatever/ like in
https://en.wikipedia.org/wiki/Generic_programmingI read something related in "
Generic programming is a style of
computer programming in which
algorithms are written in terms of
types to-be-specified-later that are then
instantiated when needed for specific types provided as
parameters."
...
to-be-specified-later... runtime leaks in the static type system, mostly a question of pov.
- <t> behaves like interface{} value type, because it does still say absolutely nothing. Not because it lacks of identity, but because it represents too many possible type.
- <t:Interface> is a shorthand to avoid a, probably, very repetitive type assert in order to use a <t>, much like an interface{}, but better, because its shorter
- <t> can be use only in func/method parameter (
excluded receiver) ? I have not been able to find it meaningful elsewhere.
- if you don t need to return the input type, you don t need <t>
- ultimately, []interface{} == []<t>, they both are list of stuff we have no idea what its about, but <t> has no sense if it is not scoped to a function call stack.
- ultimately, []<t:Stringer> does not make sense.
- when you receive a func (x <t>) <t> {}, it does actually says nothing to you, the declarer of the func, not because it lacks of identity, but because it represents too many possible types. If you d want to do something of it, you need to type assert it, to narrow it to something meaningful.
- when you receive a constrained <t:Interface>, you can work on value of type Interface, and you can return whatever, including the input parameter type
- when you call a func with a constrained type, you can actually statically verify that the input value satisfies the constraint.
- when you call a <t>, anything is as good as nil (i guess)