# Show for supertype

**URL:** <https://discourse.julialang.org/t/show-for-supertype/5375>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 14, 2017, 12:39pm UTC](https://discourse.julialang.org/t/show-for-supertype/5375 "2017-08-14T12:39:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 14, 2017, 12:39pm UTC](https://discourse.julialang.org/t/show-for-supertype/5375/1 "2017-08-14T12:39:20Z")

</div>

I am trying to organize printing for a set of types the following way: a generic function returns a string representation, then `show` for the supertype just prints it. MWE:

```julia
abstract type MyAbstractFun <: Function end
Base.show(io::IO, f::MyAbstractFun) = println(io, representation(f))
struct One <: MyAbstractFun end
(::One)(x) = x+1
representation(::One) = "just adds one"

```

but then evaluating at the REPL (ie going through `display`) gives me the standard printing from `Base`, while `show` works correctly:

```julia
julia> One()
(::One) (generic function with 1 method)

julia> show(One())
just adds one

```

Is this a bug, or am I doing something wrong?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [August 14, 2017, 12:51pm UTC](https://discourse.julialang.org/t/show-for-supertype/5375/2 "2017-08-14T12:51:45Z")

</div>

```julia
Base.show(io::IO, ::MIME"text/plain", f::MyAbstractFun) = println(io, representation(f))

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 14, 2017, 1:00pm UTC](https://discourse.julialang.org/t/show-for-supertype/5375/3 "2017-08-14T13:00:05Z")

</div>

Thanks. However, [the documentation](https://docs.julialang.org/en/latest/manual/types/#Custom-pretty-printing-1) is confusing since it suggests that the two-argument `show` method would be sufficient (which it is, when `Function` is not a supertype, in which case `show(io::IO, ::MIME"text/plain", ::Function)` is called).

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [August 14, 2017, 1:26pm UTC](https://discourse.julialang.org/t/show-for-supertype/5375/4 "2017-08-14T13:26:00Z")

</div>

I’m not sure what is confusing. It says that you can change the behavior of show when e.g. it is in the repl by defining show for the mime type. And you inherit from a type that does this. If you didn’t want the functionality from the type, why did you inherit from it?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 14, 2017, 1:37pm UTC](https://discourse.julialang.org/t/show-for-supertype/5375/5 "2017-08-14T13:37:38Z")

</div>

The confusing part is the following: the manual suggests that `show(::IO, ::MyType)` be used for basic custom printing, and the 3-argument `show` is only necessary for multi-line formats. Which is true, _except_ when the `MyType <: T` and the 3-argument `show` is defined for `T`. In which case the 2-argument `show` is not called by `display`.
