# Overload \`show\` for array of custom types

**URL:** <https://discourse.julialang.org/t/overload-show-for-array-of-custom-types/9589>\
**Category:** General Usage\
**Created:** [March 8, 2018, 8:16am UTC](https://discourse.julialang.org/t/overload-show-for-array-of-custom-types/9589 "2018-03-08T08:16:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iagoba\_Apellaniz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iagoba_apellaniz/32/34406_2.png) [@Iagoba\_Apellaniz](https://discourse.julialang.org/u/Iagoba_Apellaniz)\
**Post date:** [March 8, 2018, 8:16am UTC](https://discourse.julialang.org/t/overload-show-for-array-of-custom-types/9589/1 "2018-03-08T08:16:32Z")

</div>

Hello everyone, I’m trying to overload the `Base.show` method for arrays of custom types. I have an alternative solution that is to wrap the array into a new type, but I find it no sense.

Here is the thing

```nohighlight
julia> struct MyType
       i::Int
       end

julia> MyType(3)
MyType(3)

julia> [MyType(2), MyType(3)]
2-element Array{MyType,1}:
 MyType(2)
 MyType(3)

```

Let’s print something for when creating instances of `MyType`

```nohighlight
julia> Base.show(io::IO, x::MyType) = begin
       print(io, "Hello custom element")
       end

julia> MyType(2)
Hello custom element

```

Everything is fine until now, but when I try to overload the show function for the array…

```julia
julia> Base.show(io::IO, x::Array{MyType,1}) = begin
       print(io, "Hello array of custom elements")
       end

julia> [MyType(2), MyType(3)]
2-element Array{MyType,1}:
 Hello custom element
 Hello custom element

```

How can I solve that? Is it possible? (I think it is, everything can be solved AFAIK) Thanks!!

---

<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:** [March 8, 2018, 9:15am UTC](https://discourse.julialang.org/t/overload-show-for-array-of-custom-types/9589/2 "2018-03-08T09:15:17Z")

</div>

You can define

```julia
Base.show(io::IO, ::MIME"text/plain", ::Vector{MyType}) =
    print(io, "Hello array of custom elements")

```

and it will work. The problem seems to be that there is a [3-argument `show`](https://github.com/JuliaLang/julia/blob/d386e40c17d43b79fc89d3e579fc04547241787c/base/replutil.jl#L140) defined for `AbstractArray`s which is called by `display` instead of your method. I think this is a known issue, but I can’t locate it ATM.

Also, on how you can find this out: use `@edit` and similar.

Cf. [this discussion](https://discourse.julialang.org/t/how-to-print-arrays-inside-functions/4091).
