[Haskell-cafe] ordering of structured values

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Fri Aug 19 15:54:52 UTC 2016


On Fri, Aug 19, 2016 at 05:49:30PM +0200, Paolino wrote:
> An example on sorting (Ord a, Ord b, Ord c) => [(a,(b,c)] with 'a' in
> opposite order, then 'c' and 'b' in ascending order goes like
> 
> sortBy (comparings [Descending fst, Ascending $ snd . snd, Ascending $ fst
> . snd])

The answer is: Yes! Haskell can do that:

    sortBy (flip (comparing fst)
            <> comparing (snd . snd)
            <> comparing (fst . snd))
    
      :: (Ord a, Ord b, Ord a1) => [(a, (a1, b))] -> [(a, (a1, b))]


More information about the Haskell-Cafe mailing list