No. I mean an object where assignment creates an alias (a second pointer to the same contents). If the object supports ‘.=’, it is a container type, so struct and array qualify. So does Dict:
julia> adict= Dict{String,Int64}("O" => 1, "T" => 2); bdict=adict; bdict["O"]=99; adict
Dict{String,Int64} with 2 entries:
"T" => 2
"O" => 99
Same for arrays. but of course for scalars,
julia> ascalar= 12; bscalar= ascalar; bscalar= 99; ascalar
12
If the scalar contents had been stored at a pointed-to destination (like an array, dict, struct, etc.), then ascalar would also have turned into 99. (Still thinking in C, I mean the difference between an object which is internally stored as a pointer to the actual content, vs an object where we store the content and not a pointer.)
Incidentally, why don’t we call it a struct rather than a composite? are there other composites than stucts?
I can not only create a struct a::Union{Float64,Missing}; end
, I can also create an array of Vector{ Union{Float64,Missing}}
. I now understand that I cannot create a scalar with this type. This obviates my question about whether a union is primitive or not.
now, an array seems to be a sequential bitpattern (in C), plus some header info. why does it not take more space to store a Union array if it is not simple bit-patterns? how does Julia internally store Unions?
julia> typeof( Vector{Float64}( [ 1.0, 3.0, 2.0 ] ) )
Array{Float64,1}
julia> sizeof( Vector{Float64}( [ 1.0, 3.0, 2.0 ] ) )
24
julia> typeof( Vector{Union{Float64,Missing}}( [ 1.0, 3.0, 2.0 ] ) )
Array{Union{Missing, Float64},1}
julia> sizeof( Vector{Union{Float64,Missing}}( [ 1.0, 3.0, 2.0 ] ) )
24