You’re reading the wrong part of the manual :)
The missing piece of the puzzle is that, from your example, Array{Float64,1}
<: Array{Real,1} is *not true*, and therefore, the invocation p(2.3, [1,
1.5]) *does not* match the method definition p(x::Real, coef::Array{Real,1});
the first argument x matches, because isa(1, Real) is true, but the second
argument doesn’t match, because typeof([1, 1.5]) == Array{Float64,1}, and
therefore isa([1, 1.5], Array{Real,1}) is *false*.
Note that this doesn’t make this method definition for p uncallable; you
can still do e.g. p(2.3, Real[1, 1.5]) and it will work.
// T
On Thursday, October 8, 2015 at 11:35:05 AM UTC+2, le…@neilson-levin.org
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.
>