Sorting Any arrays is no problem as long as all the pairs of element types are comparable. For example:
julia> sort({2,1,3,pi,e})
julia> sort({2,1,3,pi,e,NA})
type error: non-boolean (NAtype) used in boolean context
in insertionsort! at sort.jl:141
in mergesort! at sort.jl:223
The sorting issue for NA is that the isless function should never return NA, unlike the < function, which can do do. Here's the pinpointed problem:
For comparison, consider NaN, which is <-unordered with respect to all numbers:
The isless function exists precisely to give a sorting order, however, otherwise all your sorts would fail in the presence of NaNs, since comparison sorts don't work if the ordering function isn't total. NaNs sort to the end, so all other numbers are isless than NaN:
Another subtlety here is that the isless and isequal comparisons need to be compatible with hashing. You can't have two things be isequal and hash differently because the isequal comparison is what is used for hashing. This implies, e.g. that -0.0 and 0.0, which are distinct IEEE 754 values such that -0.0 sorts before 0.0 must not hash the same since they cannot be isequal because isless(-0.0,0.0).
Sorry to drop all that insanity on you guys. Sorting, hashing, and floating-point numbers have a very complicated relationship. I suspect that NA should probably mostly behave like NaN in that regard, although, of course, it's distinct from NaN as well (NaN is a *known* value that is not a number, whereas NA is an unknown value).