I am hoping to create a function that will dispatch on the type I put in. Basically the function will look at the fields of the structure and do things based on the number of fields and the fieldnames. As a MWE I would like to be able to print the type. I show a few tries here
julia> Complex <: Number
true
julia> function foo(type::Number)
println(type)
end
foo (generic function with 2 methods)
julia> foo(Complex)
ERROR: MethodError: no method matching foo(::Type{Complex})
Closest candidates are:
foo(::Real) at REPL[9]:1
foo(::Number) at REPL[11]:1
Stacktrace:
[1] top-level scope
@ REPL[12]:1
julia> function foo(type::T) where T<:Number
println(type)
end
foo (generic function with 2 methods)
julia> foo(ComplexF64)
ERROR: MethodError: no method matching foo(::Type{ComplexF64})
Closest candidates are:
foo(::Real) at REPL[2]:1
foo(::T) where T<:Number at REPL[5]:1
Stacktrace:
[1] top-level scope
@ REPL[6]:1
Is this possible? How would I do it?
Thanks in advance!