Pretty print of type


Hi all,
I would like to know if it is possible to customize the output of the typeof function for a user defined struct ? I have rather long type names (recursive types) and I would like to simplify the error messages.
Thank you for your help.


This is a straightforward application of custom pretty printing to the Type{...} singleton:

julia> struct Foo; end

julia>, ::Type{Foo}) = print(io, "this is a Foo type")

julia> x = Foo()
this is a Foo type()

julia> typeof(x)
this is a Foo type

You can use T::Type{<:Foo} to handle a whole set of types.

(Beware that changing show for types should not throw, however, and in general is a finicky low-level thing. In that thread, @JeffBezanzon says I never condone defining show for particular types, which goes beyond “type piracy” and into “type treason”)


Thanks a lot ! I have tout pickup my english dictionnary to make sure I have understood the warning.