I defined two methods of a function, which I thought will have different type signatures:
foo((a, b)) = print(a, "--", b)
foo(a) = print(a)
but I’m getting:
julia> methods(foo)
# 1 method for generic function "foo":
[1] foo(a) in Main at REPL[13]:1
instead of expected two methods:
foo(::Any)
foo(Tuple{::Any, ::Any})
Why is that? Also, why the listing is different with a single method (foo(a)
) vs. multiple methods (foo(::Any)
)?
When I add:
foo(t::Tuple{Any, Any}) = print(t[1], "----", t[2])
I get:
julia> methods(foo)
# 2 methods for generic function "foo":
[1] foo(t::Tuple{Any,Any}) in Main at REPL[20]:1
[2] foo(::Any) in Main at REPL[17]:1
but when I add:
foo((a, b)::Tuple{Any, Any}) = print(a, "---", b)
it redefines the last method and shows:
julia> methods(foo)
# 2 methods for generic function "foo":
[1] foo(::Tuple{Any,Any}) in Main at REPL[23]:1
[2] foo(::Any) in Main at REPL[17]:1
so the type signature foo(t::Tuple{Any,Any})
was redefined by foo(::Tuple{Any,Any})
. Why a slightly different notation?