[Haskell-cafe] ordering of structured values

Paolino paolo.veronelli at gmail.com
Fri Aug 19 16:16:14 UTC 2016


That was easy, thank you !

paolino

2016-08-19 17:54 GMT+02:00 Tom Ellis <
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk>:

> 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))]
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160819/fc4be0b2/attachment.html>


More information about the Haskell-Cafe mailing list