Why do functions whose arguments are named tuples fail when one element of the named tuple has type Any?

To fix the dispatch you can do this:

julia> function foo(nt::NamedTuple{(:A, :V), Tuple{A,V}}) where {A,V}
       ...    
       end

But with your function body you will still get an error, because, in your original definition A and V are not defined. With my correction A and V are types which will error now in your println call.

So I guess what you want to do with this examples:

function foo(nt::NamedTuple{(:A, :V), Tuple{A,V}}) where {A,V}
    println( string(nt[:A]) * " is type " * string(A) * " and " * string(nt[:V]) * " is type " * string(V) )
end
julia> foo((A = "Hello", V = 1))
Hello is type String and 1 is type Int64

julia> foo((A = "Hello", V = 1.0))
Hello is type String and 1.0 is type Float64

julia> foo((A = "Hello", V = "world"))
Hello is type String and world is type String
1 Like