import Data.List (group, sort) mode :: (Ord a) => [a] -> [a] mode xs = map fst $ filter ((==best).snd) counts where counts = map (\l -> (head l, length l)) . group . sort $ xs best = maximum (map snd counts)