X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Flib%2Fstd%2FList.lhs;h=93640a452de9ae08c114cd78b72ba5cca3bccd74;hb=ea138284b7343bb1810cfbd0284a608dc57f7d46;hp=709687a56f45187dcba8f968fd6e6bca6e41c8a2;hpb=d033cb52223c34095c9ab201158b9008bcba9d8b;p=ghc-hetmet.git diff --git a/ghc/lib/std/List.lhs b/ghc/lib/std/List.lhs index 709687a..93640a4 100644 --- a/ghc/lib/std/List.lhs +++ b/ghc/lib/std/List.lhs @@ -1,8 +1,10 @@ +% ----------------------------------------------------------------------------- +% $Id: List.lhs,v 1.12 2001/06/25 13:13:58 simonpj Exp $ % -% (c) The AQUA Project, Glasgow University, 1994-1999 +% (c) The University of Glasgow, 1994-2000 % -\section[List]{Module @Lhar@} +\section[List]{Module @List@} \begin{code} module List @@ -65,7 +67,7 @@ module List , genericIndex -- :: (Integral a) => [b] -> a -> b , genericReplicate -- :: (Integral a) => a -> b -> [b] - , unfoldr -- :: (a -> Maybe (b,a)) -> a -> (a,[b]) + , unfoldr -- :: (b -> Maybe (a, b)) -> b -> [a] , zip4, zip5, zip6, zip7 , zipWith4, zipWith5, zipWith6, zipWith7 @@ -207,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