\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
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}
%*********************************************************
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