Type of function arguments ignored


julia> function myplus(x::UInt,y::UInt)
myplus (generic function with 2 methods)

julia> myplus(3,-4)

julia> myplus(im,-4π) == im+-4π

Since I “declared” x and y as natural numbers, should it not throw an exception if one fills in non-natural numbers?

Possibly, I don’t understand what :: does in this context.

I’m using Julia 0.7.0-DEV.3686.


Restart your julia and try again. Looks like you have another method definition this session.


Note that Julia is telling you that the myplus function has two methods defined on it. You can see what those methods are with methods(myplus). And you can see which method a set of arguments will use with @which myplus(3, -4).


Thanks, it was indeed solved by restarting Julia.

It must have been another method, indeed. I was not realising I am defining multiple methods to myplus when redefining it with different types. That could be quite useful!


Useful indeed. In fact, this is one of the fundamental ideas of Julia: https://docs.julialang.org/en/stable/manual/methods/