Thanks.
I am sure I don’t understand metaprogramming with Julia.
For example, the <: Any seems unnecessary. By not supplying a concrete or abstract type for T, T can stand for any type. Leaving out <: Any, I get the same type alias you created.
julia> using Missings
julia> const M{T} = Union{Missing, T} where T
Union{Missings.Missing, T} where T
Then, I also don’t understand what to do with this type. I can’t use it in an array constructor, for example:
julia> using Missings
julia> const M{T} = Union{Missing, T} where T <: Any
Union{Missings.Missing, T} where T
julia> b = Array{M{T},1}([1,2,3,missing])
*ERROR:* UndefVarError: T not defined
I note that in making a comparison to the type alias, I have to fill in T. it’s beginning to sink in, maybe, that a type declaration that references a type variable (T), is a little like a function in usage (but, otherwise not at all). The type variable is a parameter that has to be filled in. See at the end…
julia> using Missings
julia> const M{T} = Union{Missing, T} where T <: Any
Union{Missings.Missing, T} where T
julia> b = Array{M{T},1}([1,2,3,missing])
*ERROR:* UndefVarError: T not defined
julia> b = [1,2,3,missing]
4-element Array{Union{Int64, Missings.Missing},1}:
1
2
3
missing
julia> typeof(b)
Array{Union{Int64, Missings.Missing},1}
julia> eltype(b)
Union{Int64, Missings.Missing}
But, I can do this using the type alias when I fill in T with a concrete type:
julia> c = Array{M{Int64},1}([1,2,3, missing])
4-element Array{Union{Int64, Missings.Missing},1}:
1
2
3
missing
julia> d = Array{M{String},1}()
0-element Array{Union{Missings.Missing, String},1}
julia> push!(d, “foo”)
1-element Array{Union{Missings.Missing, String},1}:
“foo”
julia> push!(d, missing)
2-element Array{Union{Missings.Missing, String},1}:
“foo”
missing
I see this is the building block for a single type alias that can support all of the needed union types that a user could ever want. That simplifies things.
Still, I can’t escape the feeling that Julia is increasingly painting itself into the corner of a theoretical “demonstrator” language, a sort of ml for ML if you catch my drift. That’s certainly not the intent, and Julia works for pretty much all of what I previously did in Python, and with a lot more satisfaction.