Defining function calls on an object


I am confused about how to define function call syntax for objects.

If I have a concrete type then I can do it:

type MyConcrete end

(c::MyConcrete)(x) = "hello"

julia> cc = MyConcrete()

julia> (c::MyConcrete)(x) = "hello $x"

julia> cc(3)
"hello 3"

I thought the following was supposed to work for subtypes of an abstract type

julia> abstract AbstractTest

julia> type MyTest <: AbstractTest end

julia> (t::T){T <: AbstractTest}(x) = "hello"
function type in method definition is not a type

This may be issue, except I am not trying to define call on an abstract type itself, but rather a concrete object whose type is a subtype of a given abstract type.


This is exactly . Defining AbstractTest() is fine, defining (c::AbstractTest)() is not currently supported.


I am not trying to define (c::AbstractTest), but rather (c::ConcreteTest), for any ConcreteTest that is a subtype of AbstractTest.

EDIT: Or maybe that’s what you meant.


The two defines methods on exactly the same set of types. The error message might be different but none of them are currently supported for the same reason.