这是我的代码:
data Polindrom = Polindrom { a :: Integer,
b :: Integer,
c :: Integer } deriving (Show)
euler_4 = [ p | y <- [10..20],
z <- [10..20],
let x = y * z,
let p = Polindrom { a = y, b = z, c = x },
let s = show x,
s == reverse s]
现在我需要找到具有max'c'的euler_4元素。在Ruby中我使用过这样的结构:
}.sort { |a, b|
b[2] <=> a[2]
}[0]
我怎样才能在Haskell中获得它?
答案 0 :(得分:6)
import Data.Function
maximumBy (compare `on` c)
答案 1 :(得分:2)
maximumBy (\x y -> compare (c x) (c y))
答案 2 :(得分:1)
第三种可能性是Data.Ord.comparing
:
maximumBy (comparing c)