Given a parametric type T
I would like to print (or, equivalently, obtain as a String
) the name of this type without parameters. The purpose is pretty-printing a complicated type.
I need a generic solution, not one that depend on defining methods for particular types. Base.typename
used to work for this, but recent changes on master
broke this.
MWE of how I did it previously:
struct Foo{N} end
struct Bar{T}
x::T
end
Base.show(io::IO, b::Bar) = print(io, "Bar with $(Base.typename(typeof(b.x)))")
julia> Bar(Foo{Int}())
Bar with Foo
but note
julia> VERSION
v"1.6.0-DEV.707"
julia> Bar(Foo{Int}())
Bar with typename(Foo)
Ideally a solution would work for all versions, but I can also condition this code or use Compat
.