# Support for non-Int indices

**URL:** <https://discourse.julialang.org/t/support-for-non-int-indices/80920>\
**Category:** General Usage\
**Tags:** indexing, arrays\
**Created:** [May 11, 2022, 10:47pm UTC](https://discourse.julialang.org/t/support-for-non-int-indices/80920 "2022-05-11T22:47:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lilith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lilith/32/27492_2.png) [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Post date:** [May 11, 2022, 10:47pm UTC](https://discourse.julialang.org/t/support-for-non-int-indices/80920/1 "2022-05-11T22:47:36Z")

</div>

What is the current level of support for array indices other than `Int`? other than `Integer`? What are the plans going forward to support (or not) these?

---

<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:** [May 11, 2022, 10:51pm UTC](https://discourse.julialang.org/t/support-for-non-int-indices/80920/2 "2022-05-11T22:51:54Z")

</div>

You can use non-integer indices but if you don’t have `AbstractUnitRange` axes then you can’t be a subtype of an `AbstractArray` and expect things to work. You can just be an indexable object that behaves mostly array-like.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 12, 2022, 2:16am UTC](https://discourse.julialang.org/t/support-for-non-int-indices/80920/3 "2022-05-12T02:16:55Z")

</div>

> [@Lilith](#):
>
> What is the current level of support for array indices other than `Int` ?

What are you trying to do with non-integer indices? What would they mean for an array?

(If you are trying to denote some kind of continuous interpolation probably it makes more sense to use `f(x)` than `f[x]`. But if you define your own type of `f` object you are free to define `f[x]` to do whatever you want by overloading `Base.getindex`.)

---

<div class="post-metadata">

**Author:** ![Lilith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lilith/32/27492_2.png) [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Post date:** [May 12, 2022, 3:38am UTC](https://discourse.julialang.org/t/support-for-non-int-indices/80920/4 "2022-05-12T03:38:44Z")

</div>

> [@mbauman](#):
>
> You can use non-integer indices but if you don’t have `AbstractUnitRange` axes then you can’t be a subtype of an `AbstractArray` and expect things to work.

Is this supposed to work?

```julia
struct Three <: AbstractVector{Int} end
Base.size(::Three) = (0x3,)
Base.axes(::Three) = (0x3:0x5,)
Base.getindex(::Three, ::UInt8) = 3

three = Three();

for x in three
    println(x)
end
# 3
# 3
# 3

for i in eachindex(three)
    println(three[i])
end
# 3
# 3
# 3

println(three)
# ERROR: CanonicalIndexError: getindex not defined for Three

```

> [@stevengj](#):
>
> What are you trying to do with non-integer indices?

I’m trying to test the limits of the language, be silly, and fool around 🙂  
Practically, I’m wondering what I’m allowed to assume about AbstractArrays and AbstractVectors when writing generic code.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [May 12, 2022, 4:58am UTC](https://discourse.julialang.org/t/support-for-non-int-indices/80920/5 "2022-05-12T04:58:27Z")

</div>

> [@Lilith](#):
>
> `Base.getindex(::Three, ::UInt8) = 3`

you need to handle `::Int`:

[https://docs.julialang.org/en/v1/manual/interfaces/#man-interface-array](https://docs.julialang.org/en/v1/manual/interfaces/#man-interface-array)
