# \[Question\] specifying the type of inputs of Function

**URL:** <https://discourse.julialang.org/t/question-specifying-the-type-of-inputs-of-function/66078>\
**Category:** New to Julia\
**Created:** [August 9, 2021, 3:02pm UTC](https://discourse.julialang.org/t/question-specifying-the-type-of-inputs-of-function/66078 "2021-08-09T15:02:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zerosum](https://avatars.discourse-cdn.com/v4/letter/z/b2d939/32.png) [@Zerosum](https://discourse.julialang.org/u/Zerosum)\
**Post date:** [August 9, 2021, 3:02pm UTC](https://discourse.julialang.org/t/question-specifying-the-type-of-inputs-of-function/66078/1 "2021-08-09T15:02:28Z")

</div>

I was self-studying about specifying the type of inputs of a function.  
I came across with this example.

```julia
function Date(y::Int64, m::Int64=1, d::Int64=1)
    err = validargs(Date, y, m, d)
    err === nothing || throw(err)
    return Date(UTD(totaldays(y, m, d)))
end

```

It works perfectly fine. However, when I tried with my own example:

```julia
function test(x::Int8,y::Int8)
    return x+y
end
​
test(1,3)
​
MethodError: no method matching test(::Int64, ::Int64)

Stacktrace:
 [1] top-level scope
   @ In[38]:5
 [2] eval
   @ ./boot.jl:360 [inlined]
 [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1116

```

It turns out that there is an error coming from **Int8**. However, I don’t get it because 1 and 3 are both integers in the interval of **Int8**.

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [August 9, 2021, 3:06pm UTC](https://discourse.julialang.org/t/question-specifying-the-type-of-inputs-of-function/66078/2 "2021-08-09T15:06:13Z")

</div>

Int is an abbreviation for the system-word-sized integer. Your literal values are also of this type. Int8 is a distinct smaller type, so your literals do not match that type. In general, avoid specifying types for function argument except for dispatching to different methods.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [August 9, 2021, 3:16pm UTC](https://discourse.julialang.org/t/question-specifying-the-type-of-inputs-of-function/66078/3 "2021-08-09T15:16:12Z")

</div>

> [@Zerosum](#):
>
> in the interval of **Int8**.

that’s not how it works:

```julia
julia> Int8(8) == Int64(8)
true

julia> Int8(8) === Int64(8)
false

```

Variables have type, type of a variable is independent of what “value” they carry.

---

<div class="post-metadata">

**Author:** ![Zerosum](https://avatars.discourse-cdn.com/v4/letter/z/b2d939/32.png) [@Zerosum](https://discourse.julialang.org/u/Zerosum)\
**Post date:** [August 9, 2021, 3:20pm UTC](https://discourse.julialang.org/t/question-specifying-the-type-of-inputs-of-function/66078/4 "2021-08-09T15:20:37Z")

</div>

Thank you very much for the answers!

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [August 9, 2021, 5:09pm UTC](https://discourse.julialang.org/t/question-specifying-the-type-of-inputs-of-function/66078/5 "2021-08-09T17:09:23Z")

</div>

Just to complement previous answers, with your function defined like that, you would need to call it with arguments of type Int8, for example using the default constructor for that type with an appropriate Int64:

```julia
julia> typeof(8)
Int64

julia> typeof(Int8(8))
Int8

julia> test(Int8(1),Int8(3))
4

```
