`show` method for `Function` subtype

julia> struct MyFunction <: Function
              x
          end

julia> (f::MyFunction)(arg) = f.x*arg

julia> Base.show(io::IO, f::MyFunction) = println(io, "MyFunction with x=$(f.x)")

julia> f = MyFunction(3)
(::MyFunction) (generic function with 1 method)

julia> f
(::MyFunction) (generic function with 1 method)

julia> show(f)
f = MyFunction with x=3

The second and third to last lines invoke the show method for Functions, instead of my more specific MyFunction method. Is this a bug or a feature, and what can I do to overrule it?

I tried

julia> struct MyFunction <: Function
           x
       end

julia> (f::MyFunction)(arg) = f.x*arg

julia> Base.show(io::IO, ::MIME"text/plain", f::MyFunction) = println(io, "MyFunction with x=$(f.x)")

julia> f = MyFunction(3)
MyFunction with x=3


julia> f
MyFunction with x=3


julia> show(f)
MyFunction(3)
1 Like