Question

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]]
Était-ce utile?

La solution

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]]
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top