2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
4 \section[ListSetOps]{Set-like operations on lists}
11 #if ! defined(COMPILING_GHC)
12 , disjointLists, intersectingLists
16 #if defined(COMPILING_GHC)
19 import Util ( isIn, isn'tIn )
24 unionLists :: (Eq a) => [a] -> [a] -> [a]
29 | a `is_elem` b = unionLists as b
30 | otherwise = a : unionLists as b
32 #if defined(COMPILING_GHC)
33 is_elem = isIn "unionLists"
38 intersectLists :: (Eq a) => [a] -> [a] -> [a]
39 intersectLists [] [] = []
40 intersectLists [] b = []
41 intersectLists a [] = []
42 intersectLists (a:as) b
43 | a `is_elem` b = a : intersectLists as b
44 | otherwise = intersectLists as b
46 #if defined(COMPILING_GHC)
47 is_elem = isIn "intersectLists"
53 Everything in the first list that is not in the second list:
55 minusList :: (Eq a) => [a] -> [a] -> [a]
56 minusList xs ys = [ x | x <- xs, x `not_elem` ys]
58 #if defined(COMPILING_GHC)
59 not_elem = isn'tIn "minusList"
66 #if ! defined(COMPILING_GHC)
68 disjointLists, intersectingLists :: Eq a => [a] -> [a] -> Bool
70 disjointLists [] bs = True
71 disjointLists (a:as) bs
73 | otherwise = disjointLists as bs
75 intersectingLists xs ys = not (disjointLists xs ys)