Why does the type of an index default to Int?

question
proposal

#1

I’m wondering why functions like find return Int instead of say UInt. Indexes, as such, cannot be negative, so they should be unsigned, and the scope of UIntis much larger than an Int (not that we would need an array of length 1.8446744073709552e19). Would it make sense to have some native index type instead of the default Int?


#2

I guess that wouldn’t work for OffsetArrays.


#3

using unsigned ints for indexing would we problematic in index calculations. There are many discussions out there on the Web (for C/C++)

The greater range is (by the way) just a factor of two. This will certainly not be an issue in practice.


#4

Thanks! Good to know this has been thought of before.

I have a feeling that there should be a Venn diagram for “Why and how things are done in C/Matlab/Python” and “Why and how things are done in Julia”. The overlap between the two circles was understandably large at the beginning and diminished some with Julia’s development. I can’t help wonder if radical thoughts, such as a special UInt-y index type, are becoming more and more advantageous, separating those two circles even more apart…


#5

These kind of issues have been covered at length by core developers in old posts either on Discourse or on the former Google Groups. It would indeed be nice to collect them into a FAQ so they are easier to find.