[project @ 2001-08-29 10:12:34 by simonmar]
authorsimonmar <unknown>
Wed, 29 Aug 2001 10:12:34 +0000 (10:12 +0000)
committersimonmar <unknown>
Wed, 29 Aug 2001 10:12:34 +0000 (10:12 +0000)
update maximumBy and minimumBy in line with the revised Haskell 98 report

ghc/lib/std/List.lhs

index 93640a4..4633099 100644 (file)
@@ -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