dfa2cd023f67bec16d96c98e6eb73c0768ef77f7
[ghc-hetmet.git] / ghc / compiler / utils / ListSetOps.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
3 %
4 \section[ListSetOps]{Set-like operations on lists}
5
6 \begin{code}
7 module ListSetOps (
8         unionLists,
9         --UNUSED: intersectLists,
10         minusList
11
12    ) where
13
14 #include "HsVersions.h"
15
16 import Util     ( isIn, isn'tIn )
17 import List     ( union )
18 \end{code}
19
20 \begin{code}
21 unionLists :: (Eq a) => [a] -> [a] -> [a]
22 #ifdef REALLY_HASKELL_1_3
23 unionLists = union
24 #else
25 unionLists []     []            = []
26 unionLists []     b             = b
27 unionLists a       []           = a
28 unionLists (a:as) b
29   | a `is_elem` b = unionLists as b
30   | otherwise     = a : unionLists as b
31   where
32     is_elem = isIn "unionLists"
33 #endif
34
35 {- UNUSED
36 intersectLists :: (Eq a) => [a] -> [a] -> [a]
37 intersectLists []     []                = []
38 intersectLists []     b                 = []
39 intersectLists a      []                = []
40 intersectLists (a:as) b
41   | a `is_elem` b = a : intersectLists as b
42   | otherwise     = intersectLists as b
43   where
44     is_elem = isIn "intersectLists"
45 -}
46 \end{code}
47
48 Everything in the first list that is not in the second list:
49 \begin{code}
50 minusList :: (Eq a) => [a] -> [a] -> [a]
51 minusList xs ys = [ x | x <- xs, x `not_elem` ys]
52   where
53     not_elem = isn'tIn "minusList"
54
55 \end{code}