This modification works, but it fails sometimes:
abstract B{T}
type A{T}<:B{T}
end
type C{T}<:B{T}
end
promote_rule() = 1
promote_rule()
@assert promote_type(A{Real},C{Real}) == B{Real}
Base.promote_rule{T}(::Type{A{T}},::Type{C{T}}) = C{T}
@assert promote_type(A{Real},C{Real}) == B{Real}
@assert promote_type(A{Int},C{Int}) == C{Int}
The behavior of `promote_rule` for the abstract parametric type is
disrupted by the earlier weird non-Base `promote_rule`. (Environment:
JuliaBox)
By the way, why I can define `promote_rule`, but when I try to define
`promote_type`, it raises an error?
On Wednesday, August 26, 2015 at 5:25:50 AM UTC+2, Tim Holy wrote:
>
> Add `Base.` in front of `promote_rule`.
>
> --Tim
>
> On Tuesday, August 25, 2015 08:23:40 PM Sisyphuss wrote:
> > abstract B
> >
> > type A<:B
> > end
> >
> > type C<:B
> > end
> >
> > promote_rule(::Type{A},::Type{C}) = C
> >
> > @assert promote_type(A,C) == B
> >
> > Whether I define the promotion_rule or not, the promote_type is always
> B.
>
>