From adc02cf2e77529989959e40dd7d3afb84f7780cf Mon Sep 17 00:00:00 2001 From: simonmar <unknown> Date: Wed, 29 Aug 2001 10:12:34 +0000 Subject: [PATCH] [project @ 2001-08-29 10:12:34 by simonmar] update maximumBy and minimumBy in line with the revised Haskell 98 report --- ghc/lib/std/List.lhs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/ghc/lib/std/List.lhs b/ghc/lib/std/List.lhs index 93640a452de9..4633099db8be 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 -- GitLab