Thank you @jling and @Benny , your answers and a reread of the manual suggest to me that Julia will not implicitly call convert
in order to find a matching method. My example above was just an MWE to help me understand convert
, what I really want to do is something like:
struct MyType <: Function end
(::MyType)(x) = println("Hello $x")
Base.convert(::Type{MyType}, x::Function) = MyType()
dosomething(x::MyType, y) = println(x(y), " says hello")
dosomething(8) do x
x^2
end
which I now can see does not work because the new convert
method is not implicitly called. The main goal here is to be able to use do
syntax without changing (or adding methods to) dosomething
. Is there something akin to convert
that can be used to achieve this?