Types 为什么数组{Float64,N}不能是参数为数组{Number,N}的函数的参数?

Types 为什么数组{Float64,N}不能是参数为数组{Number,N}的函数的参数?,types,casting,julia,covariance,Types,Casting,Julia,Covariance,我发现Julia中的Array不是协变的,Number的子类型不会自动转换为超类型 我的意思是,比如 head(a::Vector{Number})=a[1]或head(a::Vector{Real})=a[1] 无法执行头([1,2,3]) 而head(a::Vector{T}),其中{T请参见手册中的这一节:这说明了这一点。请注意,head(a::Vector{T})有一个缩写形式,其中{T head(a::Vector{<:Number}) =...

我发现Julia中的
Array
不是协变的,
Number
的子类型不会自动转换为超类型

我的意思是,比如

head(a::Vector{Number})=a[1]
head(a::Vector{Real})=a[1]

无法执行
头([1,2,3])


head(a::Vector{T}),其中{T请参见手册中的这一节:这说明了这一点。请注意,
head(a::Vector{T})有一个缩写形式,其中{T
head(a::Vector{<:Number}) =...