Thanks, now I understand it.
The problem I had was this, which I imagine to exist with many other
non-computer scientists new to Julia.
This topic is discussed under the parametric type section of the manual,
and since I had not attempted to use parametric types (the things with
the mysterious T), I didn't bother to read that section. I ran into the
problem with mostly arrays, and it is not obvious that things like
Array{Any,1} is a parametric type. So it became very strange to me when
Array{Int,1} can not be passed in the place of Array{Any,1}.
On 2014年11月27日 12:19, [email protected] wrote:
It is demonstrated in the manual at
http://docs.julialang.org/en/release-0.3/manual/types/#parametric-composite-types
that parametric types do not have any relationship even if their
parameter types have some relationship. Perhaps it would be better
emphasise that and to explain it simply and clearly for the
non-*computer* scientists as something like:
Two parametric types Sometype{T1} and Sometype{T2} have no subtype or
supertype relationship even if T1 has a subtype or supertype
relationship to T2.
Cheers
Lex
On Thursday, November 27, 2014 1:37:53 PM UTC+10, John Myles White wrote:
All types do have Any as a parent.
It is clear that many people are confused about what covariance,
contravariance and invariance mean in computer science. As such, I
very strongly encourage everyone who isn't sure that they
understand Julia's type system to read through the wikipedia
article on covariance and contravariance:
http://en.wikipedia.org/wiki/Covariance_and_contravariance_%28computer_science%29
<http://en.wikipedia.org/wiki/Covariance_and_contravariance_%28computer_science%29>
Perhaps the Julia manual should have a "prerequisites" section
that lists all of the concepts that readers are assumed to already
understand.
-- John
On Nov 26, 2014, at 7:27 PM, K Leo <[email protected]
<javascript:>> wrote:
> I ran into similar mental difficulty regarding whether type Any
is a superset of any other types. I did not find anything to
read, but simply accepted the fact through painstaking experiments.
>
> I think the word "Any" here is confusing. The English
definition of it means that it ought to include any types.
Perhaps we should seek other word to define this type. Word like
"Mixed" might be more appropriate for this?
>
> On 2014年11月27日 08:17, Patrick O'Leary wrote:
>>
>> You've hit type invariance. In Julia, parametric types are
invariant--that is, Dict{ASCIIString,Float64} is not a subtype of
Dict{ASCIIString,Any}.
>>
>> For more information on why we use invariant parametric types,
search the list for "parametric invariant" or similar; there have
been a few discussions on the topic.
>>
>> Patrick
>