
16 Oct
2009
16 Oct
'09
8:37 a.m.
On Fri, Oct 16, 2009 at 8:07 AM, Daniel Fischer
You would achieve that by
tuplesort = sortBy (comparing fst)
or, eta-expanded,
tuplesort xs = sortBy (comparing fst) xs
But if you finally want to sort by the second component also (subordinate to sorting by the first component), it's much easier to go the whole way at once and use plain "sort".
For completeness sake, you can do it like that : tuplesort = sortBy (comparing fst `mplus` comparing snd) It's interesting to know how to do it if you want to sort using a different function than the compare of Ord. The "mplus" use some instances of Monoid that you'll find in Data.Monoid so don't forget to import it. -- Jedaï