# Difference between \`f(x::Vector{T\<:Integer})\` and \`f(x::Vector{T}) where T\<:Integer\`

**URL:** https://discourse.julialang.org/t/difference-between-f-x-vector-t-integer-and-f-x-vector-t-where-t-integer/28513
**Category:** New to Julia
**Created:** [September 7, 2019, 8:06pm UTC](https://discourse.julialang.org/t/difference-between-f-x-vector-t-integer-and-f-x-vector-t-where-t-integer/28513 "2019-09-07T20:06:45Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mirek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mirek/32/22197_2.png) [@mirek](https://discourse.julialang.org/u/mirek)
#### Post date: [September 7, 2019, 8:06pm UTC](https://discourse.julialang.org/t/difference-between-f-x-vector-t-integer-and-f-x-vector-t-where-t-integer/28513/1 "2019-09-07T20:06:45Z")

</div>

Hi,

I’m in the middle of reading the manual top-to-bottom and I can’t grasp the difference between:

> f(xs::Vector{\<:Integer}) = “foo”

and:

> f(xs::Vector{T}) where T\<:Integer = “bar”

Can anybody help me out? Are they basically the same thing? I’m guessing yes, because after those two definitions, julia says there is only one method for that function:

> julia\> f  
> f (generic function with 1 method)

If that’s the case, why those two forms are supported, not just one?

---

<div class="post-metadata">

### Author: ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)
#### Post date: [September 7, 2019, 8:15pm UTC](https://discourse.julialang.org/t/difference-between-f-x-vector-t-integer-and-f-x-vector-t-where-t-integer/28513/2 "2019-09-07T20:15:06Z")

</div>

You can ask julia for the answer:

```julia
julia> Tuple{typeof(f), Vector{<:Integer}} == Tuple{typeof(f), Vector{T}} where T <: Integer
true

```

In particular this is true for two reasons:  
`Vector{<:Integer}` is syntactic sugar for `Vector{T} where T<: Integer`, so the tuple of the first type declaration is:

```julia
Tuple{typeof(f), Vector{T} where T<:Integer}

```

Now, that’s equivalent to putting the `where` on the outside because `Tuple` is covariant (unlike other types in the system). It wouldn’t be true for e.g. `Ref`:

```julia
julia> Ref{T where T <: Integer} == Ref{T} where T<:Integer
false

julia> Tuple{T where T <: Integer} == Tuple{T} where T<:Integer
true

```

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [September 7, 2019, 11:34pm UTC](https://discourse.julialang.org/t/difference-between-f-x-vector-t-integer-and-f-x-vector-t-where-t-integer/28513/3 "2019-09-07T23:34:31Z")

</div>

> [@mirek](#):
>
> why those two forms are supported, not just one?

With `f(xs::Vector{T}) where T<:Integer = "bar"` the type `T` can be used in the body of the function, the syntax `f(xs::Vector{<:Integer}) = "bar"` is shorter but doesn’t give you the possibility to use the type of the elements of the argument in the body of the function (however you may have means, in this case you can call `eltype(xs)`). If you don’t need the parameter, the shorter form is…well…shorter, when you need the parameter you may have no other choice than using the longer form.

---

<div class="post-metadata">

### Author: ![mirek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mirek/32/22197_2.png) [@mirek](https://discourse.julialang.org/u/mirek)
#### Post date: [September 8, 2019, 3:18am UTC](https://discourse.julialang.org/t/difference-between-f-x-vector-t-integer-and-f-x-vector-t-where-t-integer/28513/4 "2019-09-08T03:18:27Z")

</div>

That makes sense, thank you Keno and Mosè.
