On 2013/2/22 Hailiang Wang <
hwan...@gmail.com> wrote:
> I intended to give some references of covariant and contravariance
> that I believe is relavant to this discussion.
>
> Wikipedia:
> * covariant: converting from a specialized type (Cats) to a more
> general type (Animals).
> * contravariant: converting from a general type (Shapes) to a more
> specialized type (Rectangles)
>
> In the example of this discussion, let's assume S is Url:
> type Url string
>
> Conversion from []string to []Url *is* converting from a general type
> (strings) to a more specialized type (Urls).
The Url type is not more specialized as the type "string". Both have
the same status and represent the exact same set of values. There are
natural arrows Url -> string and string -> Url, reciprocal to each
other. Only one of these arrows would exist if Url was a specialized
form of string.
Here we are talking about slices, and given a type S which is
assignable to T, the only sensible thing we can do is tranform []S to
[]T, so slices can only be covariant, but Go does not express this
covariance in its rules.
Rémy.