Good question, I would be interested in the answer myself.  If the tips 
indicate the explicit type dependency is preferred, then I guess that for 
the first form the compiler compiles a new instance of the function 
specifically for the concrete type `T`, while in the second, it presumably 
compiles to deal with a (partly) type-instable `x` within the function 
body.  

f1{R<:Real}(x::R) = -x

f1(x::Real) = x

f1 (generic function with 2 methods)

So the methods are kept separate, but I think the first form hides access 
to the second form.

On Monday, December 8, 2014 7:12:39 AM UTC+1, Igor Demura wrote:

> What exactly the difference between:
> function foo{T<:AbstractType}(x::T) = ...
> and 
> function foo(x::AbstractType) = ... ?
> Is any difference at all? The "tips" section of the docs says the second 
> is preferred. If they are the same, why first syntax? I can imagine that I 
> can benefit if I have several parameters:
> function bar{T<:AbstractType}(x::Concrete{T}, y::AnotherOf{T}, z::T) = ...
>
>

Reply via email to