views:

110

answers:

1
+7  A: 

You can use maximumBy with comparing:

module Main where

import Data.Ord (comparing)
import Data.List (maximumBy)

findMaxVal :: (Num a, Ord a, Num b, Ord b) => [((a, b), (a, b), (a, b))] -> b
findMaxVal = xWidth . maximumBy (comparing tWidth)
  where
    xWidth ((_, x1), (_, x2), _) = x2 - x1
    tWidth ((t1, _), _, (t3, _)) = t3 - t1
Travis Brown
I just used this solution myself about 30 minutes ago.
John
FYI: maximumBy uses a non-strict left-fold and can run out of memory....
Tim Perry
http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/src/Data-List.html#maximumBy and http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/src/Data-List.html#foldl1 if you care. Easy enough to plunk in a foldl' and write your own maximumBy'
Tim Perry