haskell - Finding list entry with the highest count -


i have entry data type

data entry = entry {     count :: integer,     name :: string } 

then want write function, takes name , list of entrys arguments give me entrys highest count. have far is

searchentry :: string -> [entry] -> maybe integer searchentry _ [] = nothing searchentry name1 (x:xs) =     if name x == name1        (count x)        else searchentry name xs  

that gives me first entry function finds, want entry highest count. how can implement that?

my suggestion break problem 2 parts:

  1. find entries matching given name
  2. find entry highest count

you set as

entriesbyname :: string -> [entry] -> [entry] entriesbyname name entries = undefined  -- use maybe since list might empty entrywithhighestcount :: [entry] -> maybe entry entrywithhighestcount entries = undefined  entrybynamewithhighestcount :: string -> [entry] -> maybe entry entrybynamewithhighestcount name entires = entrywithhighestcount $ entriesbyname name entries 

all have implement relatively simple functions used implement getentrybynamewithhighestcount.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -