Is there some Haskell function that can take a list, say of doubles, like this:
[0.5, 0.6, 0.1, 0.7]
and return a list of integers, which represent indices of the items in order. In the above case it would be:
[2, 0, 1, 3]
NOTE: What I am trying to achieve is some function (let’s call it consistent) that can compare two lists of doubles, and tell the user if the lists’s relative ordering is consistent:
> consistent [1.0, 2.0, 3.0] [2.1 3.5 4.6]
True
> consistent [1.0, 2.0, 3.0] [3.0, 2.0, 1.0]
False
You can zip the list with
[0..]to pair each item with its index. Then you can sort that list and use map to get the second element of every pair (the index).