haskell max function
-- 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)
Are there any code examples left?
New code examples in category Haskell
-
Haskell 2022-03-17 02:30:14 string to list haskell
-
Haskell 2022-03-03 08:10:01 list length haskell
-
Haskell 2022-02-27 12:00:37 haskell return false if list empty
-
Haskell 2022-02-24 19:15:24 fibnocci code in haskell language
-
Haskell 2022-02-10 07:55:04 can't do a reify in the IO monad
-
Haskell 2022-01-31 00:20:20 remove nth element from list haskell
-
Haskell 2022-01-27 18:51:21 haskell merge lists
-
Haskell 2022-01-22 12:26:49 list comprehension haskell
-
Haskell 2021-11-15 16:39:17 cabal package from GitHub