There is a difference between an abstract type like Number and a type 
parameterized by an abstract types like Vector{Number}.

While it is true that for example Float64 is a subtype of Number it is not 
true that Vector{Float64} is a subtype of Vector{Number}.



On Thursday, October 8, 2015 at 11:35:05 AM UTC+2, [email protected] 
wrote:
>
> Thanks Tomas, but what you are saying seems to violate the manual.
>
> Here is the verbatim example:
>
> (from Chapter 12, "Methods", page 104)
>
> As you can see, the arguments must be precisely of type Float64. Other 
> numeric types, such as integers or 32- bit floating-point values, are not 
> automatically converted to 64-bit floating-point, nor are strings parsed as 
> numbers. Because Float64 is a concrete type and concrete types cannot be 
> subclassed in Julia, such a definition can only be applied to arguments 
> that are exactly of type Float64. It may often be useful, however, to 
> write more general methods where the declared parameter types are abstract: 
>
>
> julia> f(x::Number, y::Number) = 2x - y;
>
> julia> f(2.0, 3)1.0
>
>
> This method definition applies to any pair of arguments that are instances 
> of Number. They need not be of the same type, so long as they are each 
> numeric values. The problem of handling disparate numeric types is 
> delegated to the arithmetic operations in the expression2x - y. 
>
>
> Can't see how that is different than my use of the abstract type Real.  In 
> fact, the above example from the manual naturally works with Real.
>
>
> Is there something special about one-line function definitions?
>
> I think my objection stands unless there are more rules or I missed 
> something and defined the function incorrectly or did the type restriction 
> incorrectly.
>
> Still confused.
>

Reply via email to