Is there any way to switch the "visible" type - the thing that is 
dispatched on - at runtime?

For example, you might think that a Union() could do this, but the 
"visible" type is either always be the Union, and not either of the 
subtypes, or doesn't allow the value to be changed.

julia> type A{T<:Union(Void,Int)} a::T end

julia> A(1)
A{Int64}(1)

julia> A(nothing)
A{Void}(nothing)

julia> A(nothing).a = 1
ERROR: ...

julia> A{Union(Void,Int)}(nothing).a = 1
1

Not sure if those examples make things clear, but when the type of A is 
explicitly A{Void} then the contents cannot be changed to an Int.  And if 
the type is explicitly A{Union(...)} then the value can be changed, but the 
"visible" type remains the Union and cannot be dispatched on.

Thanks,
Andrew



Reply via email to