julia中的函数签名

julia中的函数签名,julia,Julia,我感兴趣的是理解以下两个函数定义之间的实际差异(如果有的话) function foo(n::Integer) println("hello") end function foo{T<:Integer}(n::T) println("hello") end 函数foo(n::Integer) println(“你好”) 结束 函数参数上的函数foo{T参数用于方法消歧,而不是性能 要认识到的关键是,只定义通用的addone(x)=x+one(x)不会对性能造成影响,因为

我感兴趣的是理解以下两个函数定义之间的实际差异(如果有的话)

function foo(n::Integer)
    println("hello")
end

function foo{T<:Integer}(n::T)
    println("hello")
end
函数foo(n::Integer) println(“你好”) 结束
函数参数上的函数foo{T参数用于方法消歧,而不是性能

要认识到的关键是,只定义通用的addone(x)=x+one(x)不会对性能造成影响,因为Julia将根据需要自动编译专门的版本。例如,第一次调用addone(12),Julia将为x::Int参数自动编译专门的addone函数,并调用one()替换为其内联值1。因此,上面addone的前三个定义是完全冗余的

编辑以处理评论:

只有当存在多个参数时,两个签名之间的差异才真正明显

考虑两个功能:

julia> function foo(n::Integer, m::Integer)
           println(typeof(n), typeof(m))
       end

julia> function foo{T<:Integer}(n::T, m::T)
           println("Parameterized: ", typeof(n), typeof(m))
       end

谢谢,我明白你的意思,但它只回答了我问题的一部分。我承认,我的例子很琐碎。但我在base Julia中看到了这两种形式,并想知道它们之间的区别。因此,本质上,在一个单独的论点中,两种形式都是等价的,第一种形式需要更少的键入。谢谢。
julia> foo(1, 2)
Parameterized: Int64Int64

julia> foo(1, Int32(1))
Int64Int32