Possible Duplicate:
Sort a list of tuples by their second elements
Hey there i have a list of tuples that looks like this
[("x", [1,2,3]), ("y", [1,2]), ("z", [1,2,3,4])]
i want to sort the list in increasing order according to the length of the integer list which is the 2nd element in the tuple, however my haskell is poor at best and i cannot figure out a way to do this.
Most of the sorting problems could be solved with
sortBy ::(a -> a -> Ordering) -> [a] -> [a]function. So the task is to generate ordering function which compares two elements based on length of second element of the tuple.compare `on` (length . snd) :: (a1, [a]) -> (a1, [a]) -> Orderingis what we actually need.