Frage

I want to sort the elements of a Haskell list in lexicographic order, Is there any method?

Before sorted:

[ [], [1,2], [1], [1,2,3], [2], [1,3], [2,3], [3]]

After sorted:

[ [], [1], [1,2], [1,2,3], [1,3], [2], [2,3], [3]]
War es hilfreich?

Lösung

The default Ord instance for lists actually works that way:

Prelude> import Data.List
Prelude Data.List> sort [ [], [1,2], [1], [1,2,3], [2], [1,3], [2,3], [3]]
[[],[1],[1,2],[1,2,3],[1,3],[2],[2,3],[3]]
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top