# Defining function calls on an object

**URL:** <https://discourse.julialang.org/t/defining-function-calls-on-an-object/873>\
**Category:** Offtopic\
**Created:** [December 11, 2016, 10:48pm UTC](https://discourse.julialang.org/t/defining-function-calls-on-an-object/873 "2016-12-11T22:48:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [December 11, 2016, 10:48pm UTC](https://discourse.julialang.org/t/defining-function-calls-on-an-object/873/1 "2016-12-11T22:48:13Z")

</div>

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

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

```julia
type MyConcrete end

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

julia> cc = MyConcrete()
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
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 [https://github.com/JuliaLang/julia/issues/14919](https://github.com/JuliaLang/julia/issues/14919), 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.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [December 11, 2016, 11:05pm UTC](https://discourse.julialang.org/t/defining-function-calls-on-an-object/873/2 "2016-12-11T23:05:48Z")

</div>

This is exactly [https://github.com/JuliaLang/julia/issues/14919](https://github.com/JuliaLang/julia/issues/14919) . Defining `AbstractTest()` is fine, defining `(c::AbstractTest)()` is not currently supported.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [December 11, 2016, 11:13pm UTC](https://discourse.julialang.org/t/defining-function-calls-on-an-object/873/3 "2016-12-11T23:13:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [December 11, 2016, 11:36pm UTC](https://discourse.julialang.org/t/defining-function-calls-on-an-object/873/4 "2016-12-11T23:36:51Z")

</div>

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.
