function foo4(x,y)

is also a valid way that allows most flexibility. From a performance point 
of view all functions are equally fast.
Specifying types is not done for performance reasons but to allow for 
dispatching on the type. foo2 and foo3 are of course semantically different 
because foo2 requires that the types of both parameters equal. And foo2 
also explains why the syntax in foo1 is not sufficient to express that all 
the parameters have the same type.

Cheers,

Tobi

Am Dienstag, 19. August 2014 20:30:42 UTC+2 schrieb Spencer Lyon:
>
> Suppose I am defining a function that operates on any two real numbers. 
> Which of the following ways of specifying types is preferred (in terms of 
> idomatic Julia and performance considerations) and why?
>
> ```julia
>
> function foo1(x::Real, y::Real) = ...
>
> function foo2{ T<: Real}(x::T, y::T) = ...
>
> function foo3{T <: Real, S <: Real}(x::T, y::S) = ...
> ```
>
>

Reply via email to