Haskell Max Function

[Solved] Haskell Max Function | Haskell - Code Explorer | yomemimo.com
Question : haskell max function

Answered by : al-arafat-tanin

-- 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)

Source : https://stackoverflow.com/questions/45917027/haskell-max-number-in-a-list | Last Update : Sat, 19 Jun 21

Answers related to haskell max function

Code Explorer Popular Question For Haskell