Hey everyone. I’ve been curious for a while about the performance implications and behavior of the following types of structs:
struct MyType1{Int64,Float64}
a::Int64
b::Float64
end
versus
struct MyType2{T1<:Int64,T2<:Float64}
a::T1
b::T2
end
Also,
struct MyType3{Int64,Float64}
a
b
end
It seems like MyType1
and MyType2
are identical in all respects; is this right? Also, evidently I can’t construct an instance of type MyType3, which I didn’t expect (“no method matching” error).
It also raises a question about the relationship between the typed elements in a field and the type annotation of the struct. What is the default behavior here? For example,
struct MyBizarreType{Int64,Float64}
a::Float64
b::Int64
end
dump(MyBizarreType(1,1.0))
# MyBizarreType{Float64,Int64}
# a: Int64 1
# b: Float64 1.0
dump(MyBizarreType(1.0,1))
# MyBizarreType{Int64,Float64}
# a: Float64 1.0
# b: Int64 1
seems like it’s applying some non-obvious rules, which is puzzling especially in relation to the behavior in MyType3
.
Thanks in advance for the help!