📜  haskell max 函数 - Haskell 代码示例

📅  最后修改于: 2022-03-11 14:53:35.184000             🧑  作者: Mango

代码示例1
-- fold the list:

maximum' :: Ord a => [a] -> a
maximum' = foldr1 (\x y ->if x >= y then x else y)

--For the recursive version (no double checking):

maximum'' :: Ord a => [a] -> a
maximum'' [x]       = x
maximum'' (x:x':xs) = maximum' ((if x >= x' then x else x'):xs)

-- If you want wards:

maximum'' :: Ord a => [a] -> a
maximum'' [x]       = x
maximum'' (x:x':xs) | x >= x'   = maximum' (x:xs)
maximum'' (x:x':xs) | otherwise = maximum' (x':xs)