From: simonmar Date: Wed, 29 Aug 2001 10:12:34 +0000 (+0000) Subject: [project @ 2001-08-29 10:12:34 by simonmar] X-Git-Tag: Approximately_9120_patches~1059 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=adc02cf2e77529989959e40dd7d3afb84f7780cf;p=ghc-hetmet.git [project @ 2001-08-29 10:12:34 by simonmar] update maximumBy and minimumBy in line with the revised Haskell 98 report --- diff --git a/ghc/lib/std/List.lhs b/ghc/lib/std/List.lhs index 93640a4..4633099 100644 --- a/ghc/lib/std/List.lhs +++ b/ghc/lib/std/List.lhs @@ -1,5 +1,5 @@ % ----------------------------------------------------------------------------- -% $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 % @@ -323,13 +323,21 @@ insertBy cmp x ys@(y:ys') GT -> y : insertBy cmp x ys' _ -> x : ys -maximumBy :: (a -> a -> a) -> [a] -> a -maximumBy _ [] = error "List.maximumBy: empty list" -maximumBy max xs = foldl1 max xs - -minimumBy :: (a -> a -> a) -> [a] -> a -minimumBy _ [] = error "List.minimumBy: empty list" -minimumBy min xs = foldl1 min xs +maximumBy :: (a -> a -> Ordering) -> [a] -> a +maximumBy _ [] = error "List.maximumBy: empty list" +maximumBy cmp xs = foldl1 max xs + where + max x y = case cmp x y of + GT -> x + _ -> 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 [] = 0