<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thanks folks.<div class=""><br class=""></div><div class="">Francesco</div><div class="">Cool - I just came to that conclusion too and did</div><div class=""><br class=""></div><div class=""><div class="">tupleOrder :: (Char, Int) -> (Char, Int) -> Ordering</div><div class="">        tupleOrder (c1, x1) (c2, x2) </div><div class="">        -- char compared by ord and a is less than b!</div><div class="">          | x1 == x2 && c1 <= c2 = GT </div><div class="">          | x1 == x2 && c1 >= c2 = LT</div><div class="">          | x1 < x2 = LT </div><div class="">          | x1 > x2 = GT</div></div><div class=""><br class=""></div><div class="">and then did sortBy.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Erlend</div><div class=""><br class=""></div><div class="">I’ll try that - Monoids have such an understated elegance. :)</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 13 Dec 2016, at 16:01, Erlend Hamberg <<a href="mailto:erlend@hamberg.no" class="">erlend@hamberg.no</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">There is a really nice solution that takes advantage of Ordering's Monoid instance (see <a href="https://wiki.haskell.org/Monoid" class="">https://wiki.haskell.org/Monoid</a>).<br class=""><br class="">The imports you need:<br class=""><br class="">import Data.List (sortBy)<br class="">import Data.Ord (Down(..), comparing)<br class="">import Data.Monoid ((<>)) -- the “mappend” operator<br class=""><br class=""></div>You can then combine two calls to `comparing` <br class=""><div class=""><br class="">sortBy (comparing  (Down . snd) <> comparing fst) xs<br class=""><br class=""></div><div class="">(`Down` is just a newtype that reverses the ordering, since you wanted the first element in descending order and the second in ascending order.)<br class=""></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Tue, 13 Dec 2016 at 16:30 Francesco Ariis <<a href="mailto:fa-ml@ariis.it" class="">fa-ml@ariis.it</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tue, Dec 13, 2016 at 02:36:39PM +0000, mike h wrote:<br class="gmail_msg">
> Hi,<br class="gmail_msg">
><br class="gmail_msg">
> I’m trying to sort a list of tuples. A char and a count of that char (Char , Int)<br class="gmail_msg">
> e.g.<br class="gmail_msg">
><br class="gmail_msg">
> [ ('r',2), ('c',2),('a', 2), ('b',3), ('f',2)]<br class="gmail_msg">
><br class="gmail_msg">
> e.g. ‘r’ occurs twice etc.<br class="gmail_msg">
> The order should be based on the count first and then ties broken by the<br class="gmail_msg">
> natural ordering of char.<br class="gmail_msg">
<br class="gmail_msg">
You should provide sortBy with an appropriate compare function, e.g.<br class="gmail_msg">
<br class="gmail_msg">
    comp (a,b) (c,d) | a > c = GT<br class="gmail_msg">
                     | -- etc etc.<br class="gmail_msg">
<br class="gmail_msg">
or go with the manky but working hack:<br class="gmail_msg">
<br class="gmail_msg">
λ> :m Data.List<br class="gmail_msg">
λ> sortOn (\(a, b) -> b*(-100) + fromEnum a) [('r',2), ('c',2),('a', 2), ('b',3), ('f',2)]<br class="gmail_msg">
[('b',3),('a',2),('c',2),('f',2),('r',2)]<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
Beginners mailing list<br class="gmail_msg">
<a href="mailto:Beginners@haskell.org" class="gmail_msg" target="_blank">Beginners@haskell.org</a><br class="gmail_msg">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" class="gmail_msg" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br class="gmail_msg">
</blockquote></div><div dir="ltr" class="">-- <br class=""></div><div data-smartmail="gmail_signature" class=""><div dir="ltr" class="">Erlend Hamberg<div class=""><a href="mailto:erlend@hamberg.no" class="">erlend@hamberg.no</a></div></div></div>
_______________________________________________<br class="">Beginners mailing list<br class=""><a href="mailto:Beginners@haskell.org" class="">Beginners@haskell.org</a><br class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners<br class=""></div></blockquote></div><br class=""></div></body></html>