Search code examples
haskellrecord

adding elements of a record type


So I have a record type:

data Box = Box { edge :: Char
                   , time1 :: [Int]
                   , time2 :: Int
                   }
             deriving Eq

and this list over here:

list_of_boxes :: [Box]

How can I sum the values for time1 in each box of the list, then find which box gives the highest value for time1?


Solution

  • This will work

    maximumBy (compare `on` sum . time1) list_of_boxes
    

    You will need to import Data.List and Data.Function.