Hm. I concur. Perhaps it's a documentation thing, but if Julia wants to be
a general purpose language it needs to have clearly defined and consistent
rules.
On Jul 4, 2014 3:10 PM, "David Moon" <[email protected]> wrote:
> Here is my take for what it is worth as an observer of the Julia language:
>
> I think your second method foo(x::Number) is unreachable because your
> first method foo{T<:Number}(x::T) is more specific and there are no
> arguments to which only the second method is applicable. Having both
> methods would make more sense if the upper bound on T was a proper
> subtype of Number.
>
> I guess that the first method is considered more specific because T could
> be a proper subtype of Number. You won't get that from the
> documentation. The key Julia concept of "more specific method" is
> completely undefined in the documentation. I spent way too much time this
> spring trying to reverse-engineer its actual definition. Eventually I
> concluded that it is impossible to state clearly and succinctly what rules
> Julia currently follows. It just does what it does, and now and then gets
> patched when someone complains and the complaint seems to have merit.
>
> This seems like an area where the language needs rethinking. Multiple
> dispatch is great, and the transitive more specific method relation seems
> like a good idea, but it needs to be based on semantics that are both easy
> to understand and don't often produce surprising results. That doesn't
> seem like an easy thing to figure out. Maybe someone should do a PhD
> thesis on it.
>
> Someone other than me should answer "When would I want to use one
> definition over the other?"
>
> On Thursday, July 3, 2014 3:16:41 PM UTC-4, Andrew McKinlay wrote:
>>
>> Why does
>> foo{T<:Number}(x::T) = 1
>> foo(x::Number) = 2
>>
>> println(foo(3))
>> result in
>> 1
>> ?
>>
>> Is there any difference between the first method definition and the
>> second?
>>
>> Does the first method completely shadow the second?
>>
>> When would I want to use one definition over the other?
>>
>