Hello all,
Data.Ord has a handy function called comparing, and its documentation
shows an example of its use.
But what if you want to sort a list of values based on multiple
criteria? It turns out there is a neat way to do this:
compareTuple = mconcat [comparing fst, comparing snd]
The default Monoid instances for Ordering and functions work exactly as
required here. (Thanks to vixey in #haskell for the hint to look at
monoids!)
To reverse the order of a criterion or a set of criteria, flip can be used:
compareTuple' = mconcat [comparing fst, flip $ comparing snd]
I think it would be really neat if these two use cases were also
described in comparing's documentation. Who is the right person to ask
this of?
Thanks in advance,
Martijn.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe