By doing
promote_rule() = 1
And then
Base.promote_rule{T}(::Type{A{T}},::Type{C{T}}) = C{T}
You are defining two different functions. Only the second one is used by
the promotion system.
The valid code is
abstract B
type A<:B
end
type C<:B
end
Base.promote_rule(::Type{A},::Type{ C}) = C
@assert promote_type(A,C) == C
Sisyphuss a écrit :
In other words, it "won't fix"?
On Wednesday, August 26, 2015 at 6:41:36 AM UTC+2, Stefan Karpinski wrote:
Don't do the first non-base definition.
On Wed, Aug 26, 2015 at 12:27 AM, Sisyphuss <[email protected]>
wrote:
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.