Adding a fallback method for all functions/callables and specific argument types

Currently, this syntax is not supported:

julia> struct MyWrapperType{T}
           wrapped::T
       end

julia> (f::Any)(t::MyWrapperType) = f(t.wrapped)
ERROR: cannot add methods to an abstract type
Stacktrace:
 [1] top-level scope at none:0

julia> (f::F)(t::MyWrapperType) where {F} = f(t.wrapped)
ERROR: function type in method definition is not a type
Stacktrace:
 [1] top-level scope at none:0

Is that because it is not possible to support or can it be introduced in a future version?

You can read up here https://github.com/JuliaLang/julia/issues/14919. I think the conclusion is still pending on whether that can be done or not.

3 Likes

I see thanks for the pointer.