orome
orome

Reputation: 48446

How do I find the ordering that sorts a list in Haskell?

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

Answers (1)

ErikR
ErikR

Reputation: 52029

Is this what you are looking for?

ordering :: Ord a => [a] -> [Int]
ordering xs = map snd $ sort (zip xs [0..])

Upvotes: 9

Related Questions