
12 Mar
2005
12 Mar
'05
8:14 a.m.
I had a go with things along this theme and came up with a couple of options, with different type signatures. I use some functions from the Data.List library. If we know that, as with Ints, we are dealing with list members that are instances of Ord, we can do: howManyEqual :: (Eq a, Ord a) => [a] -> Int howManyEqual = maximum . (0 :) . map length . group . sort Otherwise, we end up less efficient, with: howManyEqual :: Eq a => [a] -> Int howManyEqual = countEach 0 where countEach best [] = best countEach best list@(x:_) = let (xs, others) = partition (== x) list in countEach (max (length xs) best) others -- Mark