# Cannot add methods to abstract type?

**URL:** <https://discourse.julialang.org/t/cannot-add-methods-to-abstract-type/6848>\
**Category:** General Usage\
**Tags:** type, error\
**Created:** [November 2, 2017, 8:26pm UTC](https://discourse.julialang.org/t/cannot-add-methods-to-abstract-type/6848 "2017-11-02T20:26:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lostella](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lostella/32/356_2.png) [@lostella](https://discourse.julialang.org/u/lostella)\
**Post date:** [November 2, 2017, 8:26pm UTC](https://discourse.julialang.org/t/cannot-add-methods-to-abstract-type/6848/1 "2017-11-02T20:26:27Z")

</div>

I’m getting this strange error message in Julia 0.6.1 when I try doing

```julia
abstract type MyAbstractType end

function (a::MyAbstractType)()
    println(42)
end

```

which results in

```julia
ERROR: cannot add methods to an abstract type

```

However everything works fine if I do

```julia
function call(a::MyAbstractType)
    println(42)
end

struct MyConcreteType <: MyAbstractType end

obj = MyConcreteType()
call(obj) # prints "42"

```

Is this expected?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 2, 2017, 8:32pm UTC](https://discourse.julialang.org/t/cannot-add-methods-to-abstract-type/6848/2 "2017-11-02T20:32:34Z")

</div>

Some relevant reading: [https://github.com/JuliaLang/julia/issues/14919](https://github.com/JuliaLang/julia/issues/14919)

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [November 2, 2017, 8:32pm UTC](https://discourse.julialang.org/t/cannot-add-methods-to-abstract-type/6848/3 "2017-11-02T20:32:37Z")

</div>

Unfortunately, what you’re asking for in `(a::MyAbstractType)() = println(42)` is not possible (this was a breaking change from Julia v0.4 to v0.5). Instead you can either create your own function (as you’ve done) or implement the calling syntax for the concrete types:

```julia
(a::MyConcreteType)() = println(42)

```

---

<div class="post-metadata">

**Author:** ![lostella](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lostella/32/356_2.png) [@lostella](https://discourse.julialang.org/u/lostella)\
**Post date:** [November 2, 2017, 8:44pm UTC](https://discourse.julialang.org/t/cannot-add-methods-to-abstract-type/6848/4 "2017-11-02T20:44:40Z")

</div>

Oh well, I’m sure that’s for a good cause. Thank you!

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [November 2, 2017, 9:18pm UTC](https://discourse.julialang.org/t/cannot-add-methods-to-abstract-type/6848/5 "2017-11-02T21:18:43Z")

</div>

Indeed it was! The good cause was that the same change which broke this feature brought us fast, inlined anonymous functions, which in turn brought us all of the magic of super-fast broadcasting and loop fusion: [WIP: redesign closures, then generic functions by JeffBezanson · Pull Request #13412 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/13412)
