2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
4 \section[ListSetOps]{Set-like operations on lists}
8 #include "HsVersions.h"
16 , disjointLists, intersectingLists
20 #if defined(COMPILING_GHC)
23 import Util ( isIn, isn'tIn )
28 unionLists :: (Eq a) => [a] -> [a] -> [a]
33 | a `is_elem` b = unionLists as b
34 | otherwise = a : unionLists as b
36 #if defined(COMPILING_GHC)
37 is_elem = isIn "unionLists"
42 intersectLists :: (Eq a) => [a] -> [a] -> [a]
43 intersectLists [] [] = []
44 intersectLists [] b = []
45 intersectLists a [] = []
46 intersectLists (a:as) b
47 | a `is_elem` b = a : intersectLists as b
48 | otherwise = intersectLists as b
50 #if defined(COMPILING_GHC)
51 is_elem = isIn "intersectLists"
57 Everything in the first list that is not in the second list:
59 minusList :: (Eq a) => [a] -> [a] -> [a]
60 minusList xs ys = [ x | x <- xs, x `not_elem` ys]
62 #if defined(COMPILING_GHC)
63 not_elem = isn'tIn "minusList"
70 #if ! defined(COMPILING_GHC)
72 disjointLists, intersectingLists :: Eq a => [a] -> [a] -> Bool
74 disjointLists [] bs = True
75 disjointLists (a:as) bs
77 | otherwise = disjointLists as bs
79 intersectingLists xs ys = not (disjointLists xs ys)