Commit adc02cf2 authored by simonmar's avatar simonmar
Browse files

[project @ 2001-08-29 10:12:34 by simonmar]

update maximumBy and minimumBy in line with the revised Haskell 98 report
parent ed69dbe9
% ----------------------------------------------------------------------------- % -----------------------------------------------------------------------------
% $Id: List.lhs,v 1.12 2001/06/25 13:13:58 simonpj Exp $ % $Id: List.lhs,v 1.13 2001/08/29 10:12:34 simonmar Exp $
% %
% (c) The University of Glasgow, 1994-2000 % (c) The University of Glasgow, 1994-2000
% %
...@@ -323,13 +323,21 @@ insertBy cmp x ys@(y:ys') ...@@ -323,13 +323,21 @@ insertBy cmp x ys@(y:ys')
GT -> y : insertBy cmp x ys' GT -> y : insertBy cmp x ys'
_ -> x : ys _ -> x : ys
maximumBy :: (a -> a -> a) -> [a] -> a maximumBy :: (a -> a -> Ordering) -> [a] -> a
maximumBy _ [] = error "List.maximumBy: empty list" maximumBy _ [] = error "List.maximumBy: empty list"
maximumBy max xs = foldl1 max xs maximumBy cmp xs = foldl1 max xs
where
minimumBy :: (a -> a -> a) -> [a] -> a max x y = case cmp x y of
minimumBy _ [] = error "List.minimumBy: empty list" GT -> x
minimumBy min xs = foldl1 min xs _ -> y
minimumBy :: (a -> a -> Ordering) -> [a] -> a
minimumBy _ [] = error "List.minimumBy: empty list"
minimumBy cmp xs = foldl1 min xs
where
min x y = case cmp x y of
GT -> y
_ -> x
genericLength :: (Num i) => [b] -> i genericLength :: (Num i) => [b] -> i
genericLength [] = 0 genericLength [] = 0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment