Reputation: 48446
In Haskell, how do I find the ordering that sorts a given list — that is, the indices to apply to the list that would result in its being sorted?
Essentially what I'm looking for is the Haskell equivalent of Mathematica's Ordering
.
Upvotes: 1
Views: 72
Reputation: 52029
Is this what you are looking for?
ordering :: Ord a => [a] -> [Int]
ordering xs = map snd $ sort (zip xs [0..])
Upvotes: 9