# Why doesn't an argument of Vector{Vector{T} where T\<:Real} accept a variable of Vector{Vector{Int64}}?

**URL:** https://discourse.julialang.org/t/why-doesnt-an-argument-of-vector-vector-t-where-t-real-accept-a-variable-of-vector-vector-int64/10792
**Category:** New to Julia
**Created:** [May 9, 2018, 5:30am UTC](https://discourse.julialang.org/t/why-doesnt-an-argument-of-vector-vector-t-where-t-real-accept-a-variable-of-vector-vector-int64/10792 "2018-05-09T05:30:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![suiato](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suiato/32/1713_2.png) [@suiato](https://discourse.julialang.org/u/suiato)
#### Post date: [May 9, 2018, 5:30am UTC](https://discourse.julialang.org/t/why-doesnt-an-argument-of-vector-vector-t-where-t-real-accept-a-variable-of-vector-vector-int64/10792/1 "2018-05-09T05:30:55Z")

</div>

Why does the function f3 below fail, while the functions f1 and f2 succeed?  
(Jupyter 0.6.2.2, JuliaPro 0.6.2.2)

function f3(a::Vector{Vector{T} where T\<:Real})  
2a  
end

a = Vector{Vector}(3)  
for i in 1:3  
a[i] = [i, i+ 1]  
end

f3(a)  
MethodError: no method matching f3(::Array{Array{T,1} where T,1})  
Closest candidates are:  
f3(::Array{Array{T,1} where T\<:Real,1}) at In[7]:2

function f1(a::Vector{Vector})  
2a  
end

function f2(a::Vector{Vector{T} where T})  
3a  
end

---

<div class="post-metadata">

### Author: ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)
#### Post date: [May 9, 2018, 6:26am UTC](https://discourse.julialang.org/t/why-doesnt-an-argument-of-vector-vector-t-where-t-real-accept-a-variable-of-vector-vector-int64/10792/2 "2018-05-09T06:26:04Z")

</div>

Because your `a` is not a subtype of `Vector{Vector{<:Real}}` (which is a shorthand for what you write):

```julia
julia> a = Vector{Vector}(3);

julia> for i in 1:3
       a[i] = [i, i+ 1]
       end;

julia> a
3-element Array{Array{T,1} where T,1}:
 [1, 2]
 [2, 3]
 [3, 4]

```

However, this does not work either:

```julia
julia> a = Vector{Vector{Int}}(3);

julia> for i in 1:3
       a[i] = [i, i+ 1]
       end;

julia> a
3-element Array{Array{Int64,1},1}:
 [1, 2]
 [2, 3]
 [3, 4]

julia> f3(a)
ERROR: MethodError: no method matching f3(::Array{Array{Int64,1},1})
Closest candidates are:
  f3(::Array{Array{T,1} where T<:Real,1}) at REPL[1]:2

```

This finally works:

```julia
julia> a = Vector{Vector{<:Real}}(3);

julia> for i in 1:3
       a[i] = [i, i+ 1]
       end;

julia> a
3-element Array{Array{T,1} where T<:Real,1}:
 [1, 2]
 [2, 3]
 [3, 4]

julia> f3(a)
3-element Array{Array{Int64,1},1}:
 [2, 4]
 [4, 6]
 [6, 8]

```

However, what you probably wanted to do was:

```julia
function f3(a::Vector{Vector{T}}) where T<:Real
2a
end

```

then all of the above `a` will work. Search the docs or this forum for “invariance” to find enlightenment (although, it is a bit a tricky subject).

PS: please quote your code snippets using backticks `: [PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530)

---

<div class="post-metadata">

### Author: ![suiato](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suiato/32/1713_2.png) [@suiato](https://discourse.julialang.org/u/suiato)
#### Post date: [May 9, 2018, 9:23am UTC](https://discourse.julialang.org/t/why-doesnt-an-argument-of-vector-vector-t-where-t-real-accept-a-variable-of-vector-vector-int64/10792/3 "2018-05-09T09:23:02Z")

</div>

Great! Thank you 😃  
I tried it as follows, and it worked:

```julia
function f4(a::Vector{Vector{T}}) where T<:Real
    4a
end

a = Vector{Vector{Real}}(3)
for i in 1:3
    a[i] = [i, i+ 1]
end

f4(a)

```

results in

```julia
3-element Array{Array{Int64,1},1}:
 [4, 8]  
 [8, 12] 
 [12, 16]

```

Thanks for the tip, too.
