# Function not able to dispatch to a method I believed was defined

**URL:** <https://discourse.julialang.org/t/function-not-able-to-dispatch-to-a-method-i-believed-was-defined/39201>\
**Category:** New to Julia\
**Created:** [May 9, 2020, 10:57pm UTC](https://discourse.julialang.org/t/function-not-able-to-dispatch-to-a-method-i-believed-was-defined/39201 "2020-05-09T22:57:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![korowjev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/korowjev/32/6431_2.png) [@korowjev](https://discourse.julialang.org/u/korowjev)\
**Post date:** [May 9, 2020, 10:57pm UTC](https://discourse.julialang.org/t/function-not-able-to-dispatch-to-a-method-i-believed-was-defined/39201/1 "2020-05-09T22:57:11Z")

</div>

Say I defined

```julia
julia> f(x::Number, g) = g(x)
f (generic function with 1 method)

julia> f(x::Array{Number, 1}, g) = f.(x)
f (generic function with 2 methods)

julia> g(x) = 2x
g (generic function with 1 method)

```

When calling `f` one method performs as expected but the other one fails to do so:

```julia
julia> f(1,g)
2

julia> f([1,1], g)
ERROR: MethodError: no method matching f(::Array{Int64, 1}, typeof(g))
Closest candidates are:
  f(::Number, ::Any) at REPL[7]:1
  f(::Array{Number,1}, ::Any) at REPL[8]:1

```

What’s more, the body of the second method seems fine:

```julia
julia> f.([1,1],g)
2-element Array{Int64,1}:
2
2

```

So I don’t understand why the second definition of `f` does not catch the array argument?  
Thank you very much in advance for any guidance.

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [May 9, 2020, 11:07pm UTC](https://discourse.julialang.org/t/function-not-able-to-dispatch-to-a-method-i-believed-was-defined/39201/2 "2020-05-09T23:07:56Z")

</div>

You need to use `Array{<:Number, 1}` instead of `Array{Number}`. The problem is that even though `Int <: Number` is true, `Array{Int, 1} <: Array{Number, 1}` is false.

---

<div class="post-metadata">

**Author:** ![korowjev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/korowjev/32/6431_2.png) [@korowjev](https://discourse.julialang.org/u/korowjev)\
**Post date:** [May 9, 2020, 11:40pm UTC](https://discourse.julialang.org/t/function-not-able-to-dispatch-to-a-method-i-believed-was-defined/39201/3 "2020-05-09T23:40:55Z")

</div>

Thank you very much!
