# Unexpected multiple dispatch behaviour

**URL:** <https://discourse.julialang.org/t/unexpected-multiple-dispatch-behaviour/6700>\
**Category:** General Usage\
**Created:** [October 26, 2017, 12:32pm UTC](https://discourse.julialang.org/t/unexpected-multiple-dispatch-behaviour/6700 "2017-10-26T12:32:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan\_Dolinsky](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jan_dolinsky/32/31347_2.png) [@Jan\_Dolinsky](https://discourse.julialang.org/u/Jan_Dolinsky)\
**Post date:** [October 26, 2017, 12:32pm UTC](https://discourse.julialang.org/t/unexpected-multiple-dispatch-behaviour/6700/1 "2017-10-26T12:32:50Z")

</div>

Hello,

I define the following two methods:

```julia
u = [[1,1,1,1], [5,5]]

f(u::Vector{<:Number}) = println("here!")
f(u::Vector{Vector{<:Number}}) = println("there!")

```

Dispatching f() on a vector of numbers works.

```julia
f(u[1])
here!

```

Dispatching on a vector of vectors of numbers does not

```julia
f(u)
MethodError: no method matching f(::Array{Array{Int64,1},1})
Closest candidates are:
  f(!Matched::Array{Array{#s1,1} where #s1<:Number,1})
  f(!Matched::Array{#s1,1} where #s1<:Number)

```

although

```julia
Int64 <: Number
true

```

I went through the manual but the above behaviour remains unclear.

Thanks in advance.  
Jan

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [October 26, 2017, 12:37pm UTC](https://discourse.julialang.org/t/unexpected-multiple-dispatch-behaviour/6700/2 "2017-10-26T12:37:59Z")

</div>

You want

```julia
u = [[1,1,1,1], [5,5]]

f(u::Vector{<:Number}) = println("here!")
f(u::Vector{<:Vector{<:Number}}) = println("there!")

```

It’s because of the way `<:` is lowered, it just “wraps” around one set of brackets.

---

<div class="post-metadata">

**Author:** ![Jan\_Dolinsky](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jan_dolinsky/32/31347_2.png) [@Jan\_Dolinsky](https://discourse.julialang.org/u/Jan_Dolinsky)\
**Post date:** [October 26, 2017, 12:42pm UTC](https://discourse.julialang.org/t/unexpected-multiple-dispatch-behaviour/6700/3 "2017-10-26T12:42:01Z")

</div>

Thanks a lot. I think I understand now.

Best Regards,  
Jan

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [October 26, 2017, 8:20pm UTC](https://discourse.julialang.org/t/unexpected-multiple-dispatch-behaviour/6700/4 "2017-10-26T20:20:09Z")

</div>

> [@cstjean](#):
>
> It’s because of the way \<: is lowered, it just “wraps” around one set of brackets.

I thought `f(u::Vector{Vector{<:Number}})` would be short-form notation for `f(u::Vector{Vector{T}}) where {T<:Number}`.  
The latter long-form notation works as expected.  
Could this be considered a bug in the way the short-form is lowered?

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [October 26, 2017, 8:34pm UTC](https://discourse.julialang.org/t/unexpected-multiple-dispatch-behaviour/6700/5 "2017-10-26T20:34:29Z")

</div>

It was a conscious decision by @stevengj. `Vector{Vector{<:Number}}` is equivalent to `Vector{Vector{T} where T<:Number}`. The rationale is probably somewhere in:

[https://github.com/JuliaLang/julia/pull/20414](https://github.com/JuliaLang/julia/pull/20414)  
[https://github.com/JuliaLang/julia/issues/6984](https://github.com/JuliaLang/julia/issues/6984)

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [October 26, 2017, 8:55pm UTC](https://discourse.julialang.org/t/unexpected-multiple-dispatch-behaviour/6700/6 "2017-10-26T20:55:29Z")

</div>

It’s also the reason I don’t like this syntax for nested types (I’m sure people will get confused). Ref [https://github.com/JuliaLang/julia/issues/6984#issuecomment-277067068](https://github.com/JuliaLang/julia/issues/6984#issuecomment-277067068)

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [October 26, 2017, 9:28pm UTC](https://discourse.julialang.org/t/unexpected-multiple-dispatch-behaviour/6700/7 "2017-10-26T21:28:26Z")

</div>

> [@cstjean](#):
>
> Vector{Vector{\<:Number}} is equivalent to Vector{Vector{T} where T\<:Number}

Ah I think I get it now.  
The placement of `where` can be a bit tricky.  
Thanks for clarifying.
