# Separate dispatch on Type{T} for subtypes

**URL:** https://discourse.julialang.org/t/separate-dispatch-on-type-t-for-subtypes/2139
**Category:** General Usage
**Tags:** question
**Created:** [February 16, 2017, 10:18pm UTC](https://discourse.julialang.org/t/separate-dispatch-on-type-t-for-subtypes/2139 "2017-02-16T22:18:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [February 16, 2017, 10:18pm UTC](https://discourse.julialang.org/t/separate-dispatch-on-type-t-for-subtypes/2139/1 "2017-02-16T22:18:42Z")

</div>

Consider the following:

```julia
abstract A
type B <: A end
type C <: A end

Base.show(io::IO, ::MIME"text/plain", ::Type{A}) = print(io, "I'm abstract type A")
Base.show{T<:A}(io::IO, ::MIME"text/plain", ::Type{T}) = print(io, "I'm type $T, a subtype of A")

```

The first show method is not called for `A`:

```julia
julia> B
I'm type B, a subtype of A

julia> A
I'm type A, a subtype of A

```

Is it possible to dispatch separately for `A` and `B`?

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [February 16, 2017, 10:58pm UTC](https://discourse.julialang.org/t/separate-dispatch-on-type-t-for-subtypes/2139/2 "2017-02-16T22:58:30Z")

</div>

Wait for 0.6 to come out? The type system revamp in 0.6 enables the first method to be considered more specific for `A`. I think the only way to do this in 0.5 is with a branch inside the function body:

```
Base.show{T<:A}(io::IO, ::MIME"text/plain", ::Type{T}) = T === A ? print(io, "I'm abstract type A") : print(io, "I'm type $T, a subtype of A")

```

Since Julia still specializes on the exact type, the branch is completely removed when the method is compiled.

---

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [February 16, 2017, 11:26pm UTC](https://discourse.julialang.org/t/separate-dispatch-on-type-t-for-subtypes/2139/3 "2017-02-16T23:26:25Z")

</div>

Thanks Matt!
