# Pretty print of type

**URL:** <https://discourse.julialang.org/t/pretty-print-of-type/19555>\
**Category:** New to Julia\
**Created:** [January 12, 2019, 11:56am UTC](https://discourse.julialang.org/t/pretty-print-of-type/19555 "2019-01-12T11:56:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [January 12, 2019, 11:56am UTC](https://discourse.julialang.org/t/pretty-print-of-type/19555/1 "2019-01-12T11:56:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 12, 2019, 1:48pm UTC](https://discourse.julialang.org/t/pretty-print-of-type/19555/2 "2019-01-12T13:48:49Z")

</div>

This is a straightforward application of [custom pretty printing](https://docs.julialang.org/en/latest/manual/types/#man-custom-pretty-printing-1) to the [`Type{...}` singleton](https://docs.julialang.org/en/latest/manual/types/#man-singleton-types-1):

```julia
julia> struct Foo; end

julia> Base.show(io::IO, ::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](https://github.com/JuliaLang/julia/issues/29428), 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”_)

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [January 12, 2019, 2:35pm UTC](https://discourse.julialang.org/t/pretty-print-of-type/19555/3 "2019-01-12T14:35:36Z")

</div>

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