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]]
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]]
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]]