# Help understanding type error: Int64 and Number

**URL:** https://discourse.julialang.org/t/help-understanding-type-error-int64-and-number/55133
**Category:** New to Julia
**Created:** [February 12, 2021, 10:10am UTC](https://discourse.julialang.org/t/help-understanding-type-error-int64-and-number/55133 "2021-02-12T10:10:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)
#### Post date: [February 12, 2021, 10:10am UTC](https://discourse.julialang.org/t/help-understanding-type-error-int64-and-number/55133/1 "2021-02-12T10:10:03Z")

</div>

I would appreciate if someone could help me understand this. I know that in Julia you don’t have to specify types of function arguments. But if possible, I want to do it because it helps me understand the code more easily.

I defined a function with one of the arguments being a dictionary of type  
`Dict{Tuple{Number, Number}, Number}`. When I explicitly create an instance of this argument (using numerical values) Julia assigns that value the type `Dict{Tuple{Int64, Int64}, Float64}`. When I pass this value to the function I get the following error (please see argument number 3). Since both `Int64` and `Float64` are subtypes of `Number`, I thought this should work. Where am I going wrong?  
Interestingly, no such error is thrown for the first two arguments.

```julia
ERROR: MethodError: no method matching exp_payoff(::Tuple{Int64,Int64}, ::Int64, ::Dict{Tuple{Int64,Int64},Float64}, ::Int64, ::Int64, ::Set{Tuple{Int64,Int64}}, ::Distributions.Poisson{Float64}, ::Distributions.Poisson{Float64}, ::Distributions.Poisson{Float64}, ::Distributions.Poisson{Float64}, ::Float64)
Closest candidates are:
  exp_payoff(::Tuple{Number,Number}, ::Number, ::Dict{Tuple{Number,Number},Number}, ::Number, ::Number, ::Any, ::Distributions.Poisson, ::Distributions.Poisson, ::Distributions.Poisson, ::Distributions.Poisson, ::Any)

```

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [February 12, 2021, 10:16am UTC](https://discourse.julialang.org/t/help-understanding-type-error-int64-and-number/55133/2 "2021-02-12T10:16:26Z")

</div>

> [@curious](#):
>
> Since both `Int64` and `Float64` are subtypes of `Number` , I thought this should work. Where am I going wrong?

See [Types · The Julia Language](https://docs.julialang.org/en/v1/manual/types/#Parametric-Composite-Types), especially the note

> even though `Float64 <: Real` we **DO NOT** have `Point{Float64} <: Point{Real}` .

---

<div class="post-metadata">

### Author: ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)
#### Post date: [February 12, 2021, 12:47pm UTC](https://discourse.julialang.org/t/help-understanding-type-error-int64-and-number/55133/3 "2021-02-12T12:47:01Z")

</div>

Thank you @kristoffer.carlsson. That link was helpful.

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [February 12, 2021, 1:10pm UTC](https://discourse.julialang.org/t/help-understanding-type-error-int64-and-number/55133/4 "2021-02-12T13:10:20Z")

</div>

To complement, we have:

```julia
Point{Float64} <: Point{<:Real}

```

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [February 12, 2021, 2:06pm UTC](https://discourse.julialang.org/t/help-understanding-type-error-int64-and-number/55133/5 "2021-02-12T14:06:19Z")

</div>

I am writing to help and also to make things more clear to me:

When one writes `Vector{Float64}` we are referencing a vector that can _ **only** _ contain Float64 numbers. A vector of type `Vector{Real}` _ **can** _ contain any type of real number. While a `Vector{Real}` can by chance contain only `Float64` numbers, it will never have the _ **constraint** _ of only having one type of numbers. At the same time, of course, a `Vector{Float64}` will never be able to contain other type of number than `Float64`. Thus, one type of vector is not a subtype of the other, they are different things.

Horrible analogies here: In chess, the Queen can move as the Tower, but that does not make the Tower a subtype of Queen. A men’s toilet is not a unisex toilet that happens to have only men inside.

These rationale applies to _concrete_ types (that is, types that actual vectors will assume). Thus, we have:

```julia
julia> x = Real[1, 2.0];

julia> y = Float64[1.0, 2.0];

julia> typeof(y) <: typeof(x)
false

julia> typeof(x) <: typeof(y)
false

```

When one uses `<:` we are obtaining abstract types. That is why `Vector{Float64} <: Vector{<:Real}` or even `Vector{Real} <: Vector{<:Real}` are both true. We are here asking if the concrete types `Vector{Float64}` and `Vector{Real}` are subtypes of an abstract type of vector that may or not be able to contain any type of `Real` number in them. These are the comparisons we happen to have in mind when doing this kind of confusion:

1. Is a vector that can only contain `Float64` numbers a subtype of the abstract type of vectors that _may or not be able_ to contain any kind of `Real` number in them? is translated to `Vector{Float64}<:Vector{<:Real}`.

2. Is a vector that can only contain `Float64` numbers a subtype of the type of vectors than _are able_ to accept other types of `Real` numbers? is translated to `Vector{Float64}<:Vector{Real}`, and is false because `Vector{Real}` does not have the _constraint_ that the first type has.
