I would like to understand the use of methods(function, types)
. Consider the following two invocations, whose results are not the same. This implies that the order in which the types are listed in the second argument impacts the return. Is this a bug or expected behavior? Thanks.
methods(+, [Int,Float])
methods(+, [Real, Int])
methods(+, [Real,Int])
# 6 methods for generic function "+":
[1] +(x::BigInt, c::Union{Int16, Int32, Int64, Int8}) in Base.GMP at gmp.jl:527
[2] +(x::BigFloat, c::Union{Int16, Int32, Int64, Int8}) in Base.MPFR at mpfr.jl:394
[3] +(x::T, y::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} in Base at int.jl:53
[4] +(a::Integer, b::Integer) in Base at int.jl:857
[5] +(x::T, y::T) where T<:Number in Base at promotion.jl:384
[6] +(x::Number, y::Number) in Base at promotion.jl:311
methods(+, [Int,Real])
# 7 methods for generic function "+":
[1] +(x::T, y::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} in Base at int.jl:53
[2] +(c::Union{Int16, Int32, Int64, Int8}, x::BigInt) in Base.GMP at gmp.jl:528
[3] +(a::Integer, b::Integer) in Base at int.jl:857
[4] +(c::Union{Int16, Int32, Int64, Int8}, x::BigFloat) in Base.MPFR at mpfr.jl:398
[5] +(x::Integer, y::Ratios.SimpleRatio) in Ratios at /Users/erlebach/.julia/packages/Ratios/uRs4y/src/Ratios.jl:29
[6] +(x::T, y::T) where T<:Number in Base at promotion.jl:384
[7] +(x::Number, y::Number) in Base at promotion.jl:311
Here are results when I invoke methods
with a single type at a time:
methods(+,[Int])
# 1 method for generic function "+":
[1] +(x::Number) in Base at operators.jl:504
methods(+,[Real])
# 3 methods for generic function "+":
[1] +(x::Bool) in Base at bool.jl:93
[2] +(x::Rational) in Base at rational.jl:247
[3] +(x::Number) in Base at operators.jl:504
methods(+,[Int])
# 1 method for generic function "+":
[1] +(x::Number) in Base at operators.jl:504
Given these results, I would expect that using two types would generate 4 results, not 6 or 7. There is clearly something I do not understand in how methods
is supposed to work.