[Haskell-beginners] Sorting
mike h
mike_k_houghton at yahoo.co.uk
Tue Dec 13 14:36:39 UTC 2016
Hi,
I’m trying to sort a list of tuples. A char and a count of that char (Char , Int)
e.g.
[ ('r',2), ('c',2),('a', 2), ('b',3), ('f',2)]
e.g. ‘r’ occurs twice etc.
The order should be based on the count first and then ties broken by the
natural ordering of char.
So
[ ('r',2), ('c',2),('a', 2), ('b',3), ('f',2)]
will sort as
[('b',3),('a', 2), ('c',2),('f',2), ('r',2)]
I initially tried variants on
sortBy (compare `on` snd)
and then made a type Tup = T (Char, Int)
and defined Eq and then got to the point where I felt that this had become too difficult for a simple problem and concluded that I’m missing a point somewhere and need a bit of help!
Many thanks
M
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20161213/1418403f/attachment-0001.html>
More information about the Beginners
mailing list