# Why can't I use Vector{Int64} with functions expecting Vector{Integer}?

**URL:** <https://discourse.julialang.org/t/why-cant-i-use-vector-int64-with-functions-expecting-vector-integer/91779>\
**Category:** New to Julia\
**Tags:** question, type, multiple-dispatch\
**Created:** [December 17, 2022, 3:57pm UTC](https://discourse.julialang.org/t/why-cant-i-use-vector-int64-with-functions-expecting-vector-integer/91779 "2022-12-17T15:57:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Titas22](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/titas22/32/39209_2.png) [@Titas22](https://discourse.julialang.org/u/Titas22)\
**Post date:** [December 17, 2022, 3:57pm UTC](https://discourse.julialang.org/t/why-cant-i-use-vector-int64-with-functions-expecting-vector-integer/91779/1 "2022-12-17T15:57:52Z")

</div>

Hi,  
I was trying to define a function that would work on all integer types, and could not get it to work when the input is matrix or vector.

functions taking in single value of Int64 or Integer work fine. But if I call a function expecting Vector{Integer} with input of Vector{Int64} it does not work.

Is there a way to work around this? Or am I doing something wrong here?

```julia
f1(x::Integer) = display(x)
f2(x::Int64) = display(x)

f1(x::Vector{Integer}) = display(x)
f2(x::Vector{Int64}) = display(x)

v = collect(1:5);

# These work
f1(v[1])
f2(v[1])

# This also works
f2(v)

# But this doesn't
f1(v)

```

The error I get:

```julia
julia> f1(v)
ERROR: MethodError: no method matching f1(::Vector{Int64})
Closest candidates are:
  f1(::Integer) at REPL[34]:1
  f1(::Vector{Integer}) at REPL[36]:1
Stacktrace:
 [1] top-level scope
   @ REPL[45]:1

```

Thanks,  
Titas

---

<div class="post-metadata">

**Author:** ![Titas22](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/titas22/32/39209_2.png) [@Titas22](https://discourse.julialang.org/u/Titas22)\
**Post date:** [December 17, 2022, 4:24pm UTC](https://discourse.julialang.org/t/why-cant-i-use-vector-int64-with-functions-expecting-vector-integer/91779/2 "2022-12-17T16:24:02Z")

</div>

Update:

I’ve been trying a couple of different things and thought maybe I should be using `AbstractVector` for this, however the following:

```julia
f3(x::AbstractVector{Integer}) = display(x)

```

but got the same error.  
  
  
I then found found the following to work the way I expect:

```julia
f6(x::Vector{T} where T = Integer) = display(x)

```

however, this seems like a bit overcomplicated way to write this out - is there a simpler way?

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [December 17, 2022, 4:47pm UTC](https://discourse.julialang.org/t/why-cant-i-use-vector-int64-with-functions-expecting-vector-integer/91779/3 "2022-12-17T16:47:57Z")

</div>

A shorthand is `Vector{<:Integer}`.

---

<div class="post-metadata">

**Author:** ![benninkrs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/benninkrs/32/3191_2.png) [@benninkrs](https://discourse.julialang.org/u/benninkrs)\
**Post date:** [December 17, 2022, 4:48pm UTC](https://discourse.julialang.org/t/why-cant-i-use-vector-int64-with-functions-expecting-vector-integer/91779/4 "2022-12-17T16:48:30Z")

</div>

Quick answer (I am typing this from my phone): This is explained in the manual in the section on [parametric types](https://docs.julialang.org/en/v1/manual/types/#man-parametric-composite-types).

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [December 17, 2022, 5:59pm UTC](https://discourse.julialang.org/t/why-cant-i-use-vector-int64-with-functions-expecting-vector-integer/91779/5 "2022-12-17T17:59:47Z")

</div>

> [@Titas22](#):
>
> ```julia
> f6(x::Vector{T} where T = Integer) = display(x)
> 
> ```

This doesn’t do what you expect it to. I think you expected:

```julia
f6(x::Vector{T} where T <: Integer) = display(x)

```

What you actually had is:

```julia
f6( ( x::Vector{T} where T ) = Integer) = display(x)

```

i.e. `f6` takes vector `x` of **any** type, and the default value of `x` is the value `Integer`. Thus calling `f6()` invokes `f6(Integer)` which is undefined.

Use `methods(f6)` to follow which definitions are active in a session.
