From f00281df6ea1b837beb4b997ef003aa8e7cce10e Mon Sep 17 00:00:00 2001 From: simonpj Date: Mon, 25 Jun 2001 13:13:58 +0000 Subject: [PATCH 1/1] [project @ 2001-06-25 13:13:58 by simonpj] In nubBy, put argument to eq in the standard order --- ghc/lib/std/List.lhs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/ghc/lib/std/List.lhs b/ghc/lib/std/List.lhs index 399cd3b..93640a4 100644 --- a/ghc/lib/std/List.lhs +++ b/ghc/lib/std/List.lhs @@ -1,5 +1,5 @@ % ----------------------------------------------------------------------------- -% $Id: List.lhs,v 1.11 2000/08/18 06:44:05 qrczak Exp $ +% $Id: List.lhs,v 1.12 2001/06/25 13:13:58 simonpj Exp $ % % (c) The University of Glasgow, 1994-2000 % @@ -209,14 +209,18 @@ nubBy eq (x:xs) = x : nubBy eq (filter (\ y -> not (eq x y)) xs) nubBy eq l = nubBy' l [] where nubBy' [] _ = [] - nubBy' (x:xs) ls - | elemBy eq x ls = nubBy' xs ls - | otherwise = x : nubBy' xs (x:ls) - ---not exported: -elemBy :: (a -> a -> Bool) -> a -> [a] -> Bool -elemBy _ _ [] = False -elemBy eq x (y:ys) = x `eq` y || elemBy eq x ys + nubBy' (y:ys) xs + | elem_by eq y xs = nubBy' ys xs + | otherwise = y : nubBy' ys (y:xs) + +-- Not exported: +-- Note that we keep the call to `eq` with arguments in the +-- same order as in the reference implementation +-- 'xs' is the list of things we've seen so far, +-- 'y' is the potential new element +elem_by :: (a -> a -> Bool) -> a -> [a] -> Bool +elem_by _ _ [] = False +elem_by eq y (x:xs) = x `eq` y || elem_by eq y xs #endif -- 1.7.10.4