Q:

Finding list entry with the highest count

I have an Entry data type
data Entry = Entry {
    count :: Integer,
    name :: String }

Then I want to write a function, that takes the name and a list of Entrys as arguments an give me the Entrys with the highest count.  What I have so far is
searchEntry :: String -> [Entry] -> Maybe Integer
searchEntry _ [] = Nothing
searchEntry name1 (x:xs) = 
   if name x == name1
       then Just (count x)
       else searchEntry name xs 

That gives me the FIRST Entry that the function finds, but I want the Entry with the highest count. How can I implement that?

A:

My suggestion would be to break the problem into two parts:

Find all entries matching a given name
Find the entry with the highest count

You could set it up as
entriesByName :: String -> [Entry] -> [Entry]
entriesByName name entries = undefined

-- Use Maybe since the list might be empty
entryWithHighestCount :: [Entry] -> Maybe Entry
entryWithHighestCount entries = undefined

entryByNameWithHighestCount :: String -> [Entry] -> Maybe Entry
entryByNameWithHighestCount name entires = entryWithHighestCount $ entriesByName name entries

All you have to do is implement the relatively simple functions that are used to implement getEntryByNameWithHighestCount.

