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

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to