数组在Julia中破坏字符串类型 [英] Arrays break string types in Julia
问题描述
以下是设计使然吗?
ASCIIString <: String
返回true
,但是Array{ASCIIString,1} <: Array{String,1}
返回false
.
也许这是一个错误,我应该在github上发出拉取请求. (我正在运行v0.4.0-dev + 6210)
Perhaps this is a bug, and I should make a pull request on github. (I'm running v0.4.0-dev+6210)
推荐答案
只需将我的评论转换为答案即可:
just convert my comment into an answer:
您的问题的答案是是".正如julia的文档所述:
the answer to your question is YES. As julia's document says:
用类型论的话来说,朱莉娅的类型参数是不变,而不是协变(甚至是协变).
in the parlance of type theory, Julia’s type parameters are invariant, rather than being covariant (or even contravariant).
在下面的误导性案例中,人们可能会发现
in the misleading case below, one may find that
julia> Int64 <: Int
true
julia> Array{Int64,1} <: Array{Int,1}
true
这是因为Int
和Int64
是同一类型.
this is because Int
and Int64
are the same type.
julia> xdump(Int)
Int64::DataType <: Signed
julia> xdump(Int64)
Int64::DataType <: Signed
julia> xdump(Array{Int,1})
Array{Int64,1}::DataType <: DenseArray{Int64,1}
julia> xdump(Array{Int64,1})
Array{Int64,1}::DataType <: DenseArray{Int64,1}
我们可以使用typejoin
来检查类型A
和类型B
及其对应的数组"之间的关系.
we can use typejoin
to checkout the relationship between type A
and type B
and their corresponding "arrays".
julia> typejoin(Int64,Int)
Int64
julia> typejoin(Array{Int64,1},Array{Int,1})
Array{Int64,1}
但是
julia> typejoin(ASCIIString,String)
String
julia> typejoin(Array{String,1},Array{ASCIIString,1})
Array{T,N} (constructor with 9 methods)
这篇关于数组在Julia中破坏字符串类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!