
3 Mar
2007
3 Mar
'07
5:08 p.m.
On Sat, 03 Mar 2007 22:35:00 +0100, Jared Jennings
-- Sort the [a]'s by the [b]'s. sortByKeys :: (Ord b) => [b] -> [a] -> [a] sortByKeys keys values = map snd $ sortBy compareFst (zip keys values) where compareFst x y = compare (fst x) (fst y)
You can simplify that to: sortByKeys :: (Ord b) => [b] -> [a] -> [a] sortByKeys keys values = map snd $ sort $ zip keys values as "sort" also handles tuples; it is not fully identical, in case there are duplicate keys: Data.List> sort [(2, 2), (2, 1), (1, 2), (1, 1)] [(1,1),(1,2),(2,1),(2,2)] -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ -- Using Opera's revolutionary e-mail client: https://secure.bmtmicro.com/opera/buy-opera.html?AID=789433