# Dispatching on type alias

**URL:** <https://discourse.julialang.org/t/dispatching-on-type-alias/84035>\
**Category:** General Usage\
**Created:** [July 11, 2022, 6:30am UTC](https://discourse.julialang.org/t/dispatching-on-type-alias/84035 "2022-07-11T06:30:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![torrance](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torrance/32/38990_2.png) [@torrance](https://discourse.julialang.org/u/torrance)\
**Post date:** [July 11, 2022, 6:30am UTC](https://discourse.julialang.org/t/dispatching-on-type-alias/84035/1 "2022-07-11T06:30:58Z")

</div>

I want to create a type alias for the standard array type, i.e.:

```
const MyArray = Array

```

and I want to be able to dispatch on this type in a way that is unique for `MyArray`, e.g.:

```
function test(::MyArray)
    println("It's mine!")
end

function test(::Array)
    println("It ain't mine")
end

```

Presently this won’t work. `MyArray` immediately resolves to `Array` and the compiler doesn’t know about it. So in the above example, the latter definition of `test()` will always be dispatched.

Is there some kind of work around for what I want to do? I want a type that is an array type in every way and inherits all its standard functions **with the exception that I can dispatch to unique functions based on its type.**

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [July 11, 2022, 12:12pm UTC](https://discourse.julialang.org/t/dispatching-on-type-alias/84035/2 "2022-07-11T12:12:24Z")

</div>

Because with `const MyArray = Array` you’re saying `MyArray` and `Array` are the same type!

To get what you want, you need to define your own type that wraps an `Array` and forwards all the `AbstractArray` methods (which is more annoying than it could be…, see [Interfaces · The Julia Language](https://docs.julialang.org/en/v1/manual/interfaces/#man-interface-array))

Then you can dispatch on it separately.

---

<div class="post-metadata">

**Author:** ![torrance](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torrance/32/38990_2.png) [@torrance](https://discourse.julialang.org/u/torrance)\
**Post date:** [July 12, 2022, 1:46am UTC](https://discourse.julialang.org/t/dispatching-on-type-alias/84035/3 "2022-07-12T01:46:55Z")

</div>

@Raf Yup, that’s what I was trying to avoid: forwarding all those calls to the inner array isn’t especially elegant and quite annoying!

In the end, I decided it was easier to dispatch on the `eltype()` rather than the array itself, even if that means having a struct wrapping nothing but a single float value. Semantically this makes more sense for my current purposes (since this float is _kind of_ a type of unit I don’t want simply added other floats) but also the number of float methods I need to forward (in my case) is just a few.
