+% -----------------------------------------------------------------------------
+% $Id: List.lhs,v 1.11 2000/08/18 06:44:05 qrczak 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
(
+#ifndef __HUGS__
[]((:), [])
+ ,
+#endif
- , elemIndex -- :: (Eq a) => a -> [a] -> Maybe Int
+ elemIndex -- :: (Eq a) => a -> [a] -> Maybe Int
, elemIndices -- :: (Eq a) => a -> [a] -> [Int]
, find -- :: (a -> Bool) -> [a] -> Maybe a
, 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
import Prelude
import Maybe ( listToMaybe )
+
+#ifndef __HUGS__
+import PrelShow ( lines, words, unlines, unwords )
import PrelBase ( Int(..), map, (++) )
import PrelGHC ( (+#) )
+#endif
-infix 5 \\
+infix 5 \\
\end{code}
%*********************************************************
#ifdef USE_REPORT_PRELUDE
findIndices p xs = [ i | (x,i) <- zip xs [0..], p x]
#else
+#ifdef __HUGS__
+findIndices p xs = [ i | (x,i) <- zip xs [0..], p x]
+#else
-- Efficient definition
findIndices p ls = loop 0# ls
where
loop _ [] = []
loop n (x:xs) | p x = I# n : loop (n +# 1#) xs
| otherwise = loop (n +# 1#) xs
-#endif
+#endif /* __HUGS__ */
+#endif /* USE_REPORT_PRELUDE */
isPrefixOf :: (Eq a) => [a] -> [a] -> Bool
isPrefixOf [] _ = True
nub = nubBy (==)
#else
-- stolen from HBC
-nub l = nub' l []
+nub l = nub' l [] -- '
where
- nub' [] _ = []
- nub' (x:xs) ls
- | x `elem` ls = nub' xs ls
- | otherwise = x : nub' xs (x:ls)
+ nub' [] _ = [] -- '
+ nub' (x:xs) ls -- '
+ | x `elem` ls = nub' xs ls -- '
+ | otherwise = x : nub' xs (x:ls) -- '
#endif
nubBy :: (a -> a -> Bool) -> [a] -> [a]
-- predicate, respectively; i,e,,
-- partition p xs == (filter p xs, filter (not . p) xs).
partition :: (a -> Bool) -> [a] -> ([a],[a])
-partition p xs = foldr select ([],[]) xs
- where select x (ts,fs) | p x = (x:ts,fs)
- | otherwise = (ts, x:fs)
+{-# INLINE partition #-}
+partition p xs = foldr (select p) ([],[]) xs
+
+select p x (ts,fs) | p x = (x:ts,fs)
+ | otherwise = (ts, x:fs)
\end{code}
@mapAccumL@ behaves like a combination