Hey,
I am sorry if this question is either irrelevant or stupid, but I am having
problems figuring out the type promotion and conversions.
Could you please explain to me why the below code excerpt is not giving me
what I want it to return:
abstract A;
immutable A1 <: A
num::Float64
end;
immutable A2 <: A
num::Int64
end;
# conversion
A1(a::A2) = A1(a.num);
convert(::Type{A1}, a::A2) = A1(a);
# promotion
promote_rule(::Type{A1}, ::Type{A2}) = A1;
a1 = A1(1.);
a2 = A2(2);
promote(a1,a2)
julia> (A1(1.0),A2(2))
Why can I not get `(A1(1.0),A1(2.0))` for example, although the
`convert(::Type{A1}, a::A2)` method and the `A1(a::A2)` constructor
are working properly. Or, am I missing something?
I tried to follow the promotion and conversion section of documentation
<http://julia.readthedocs.org/>; however, I have not been successful so far.
Thanks!