# Define a type alias for an Array of indices that point to the array

**URL:** <https://discourse.julialang.org/t/define-a-type-alias-for-an-array-of-indices-that-point-to-the-array/56333>\
**Category:** General Usage\
**Tags:** array, parametric-types\
**Created:** [March 2, 2021, 1:33pm UTC](https://discourse.julialang.org/t/define-a-type-alias-for-an-array-of-indices-that-point-to-the-array/56333 "2021-03-02T13:33:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlbosse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlbosse/32/11274_2.png) [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Post date:** [March 2, 2021, 1:33pm UTC](https://discourse.julialang.org/t/define-a-type-alias-for-an-array-of-indices-that-point-to-the-array/56333/1 "2021-03-02T13:33:17Z")

</div>

I want to define a type alias for n-dimensional arrays of n-dimensional cartesian indices (so an array  
that holds indices that are able to index that array). I tried

```julia-repl
julia> MyType = Array{CartesianIndex{N},N} where N

```

and get as expected

```julia-repl
julia> isa([CartesianIndex(1), CartesianIndex(2)], MyType)
true

```

but unlike wanted also

```julia-repl
julia> isa([CartesianIndex(1,1), CartesianIndex(2,2)], MyType)
true

```

even though the dimensions don’t match in the second case. How do enforce that the dimensions  
match in the type alias?

**Bonus points** if I can make it `AbstractArray{CartesianIndex{N},N}` instead of `Array`. So far  
that also doesn’t work, probably because

```julia-repl
julia> Vector{Int8} <: AbstractArray{Integer}
false

```

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [March 2, 2021, 1:50pm UTC](https://discourse.julialang.org/t/define-a-type-alias-for-an-array-of-indices-that-point-to-the-array/56333/2 "2021-03-02T13:50:26Z")

</div>

Can you try on Julia 1.6rc1? I get

```julia
julia> isa([CartesianIndex(1,1), CartesianIndex(2,2)], MyType)
false

```

I also have

```julia
julia> [CartesianIndex(1), CartesianIndex(2)] isa (AbstractArray{CartesianIndex{N}, N} where N)
true

```

```julia

```

---

<div class="post-metadata">

**Author:** ![jlbosse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlbosse/32/11274_2.png) [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Post date:** [March 2, 2021, 1:59pm UTC](https://discourse.julialang.org/t/define-a-type-alias-for-an-array-of-indices-that-point-to-the-array/56333/3 "2021-03-02T13:59:51Z")

</div>

Oops, I had a comma missing between the `CartesianIndex(1,1)` and `CartesianIndex(2,2)` turning the whole thing into a (1,2)-Array. So really my fault there
