d2737a4b7f87d77f10c6f49013663c5bfcf3fcde
[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 #include "HsVersions.h"
8
9 module ListSetOps (
10         unionLists,
11         --UNUSED: intersectLists,
12         minusList
13
14    ) where
15
16 IMP_Ubiq(){-uitous-}
17
18 import Util     ( isIn, isn'tIn )
19
20 #if __GLASGOW_HASKELL__ >= 202
21 import List
22 #endif
23 \end{code}
24
25 \begin{code}
26 unionLists :: (Eq a) => [a] -> [a] -> [a]
27 #ifdef REALLY_HASKELL_1_3
28 unionLists = union
29 #else
30 unionLists []     []            = []
31 unionLists []     b             = b
32 unionLists a       []           = a
33 unionLists (a:as) b
34   | a `is_elem` b = unionLists as b
35   | otherwise     = a : unionLists as b
36   where
37     is_elem = isIn "unionLists"
38 #endif
39
40 {- UNUSED
41 intersectLists :: (Eq a) => [a] -> [a] -> [a]
42 intersectLists []     []                = []
43 intersectLists []     b                 = []
44 intersectLists a      []                = []
45 intersectLists (a:as) b
46   | a `is_elem` b = a : intersectLists as b
47   | otherwise     = intersectLists as b
48   where
49     is_elem = isIn "intersectLists"
50 -}
51 \end{code}
52
53 Everything in the first list that is not in the second list:
54 \begin{code}
55 minusList :: (Eq a) => [a] -> [a] -> [a]
56 minusList xs ys = [ x | x <- xs, x `not_elem` ys]
57   where
58     not_elem = isn'tIn "minusList"
59
60 \end{code}