2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
4 \section[ListSetOps]{Set-like operations on lists}
7 #include "HsVersions.h"
13 #if ! defined(COMPILING_GHC)
14 , disjointLists, intersectingLists
18 #if defined(COMPILING_GHC)
21 import Util ( isIn, isn'tIn )
26 unionLists :: (Eq a) => [a] -> [a] -> [a]
31 | a `is_elem` b = unionLists as b
32 | otherwise = a : unionLists as b
34 #if defined(COMPILING_GHC)
35 is_elem = isIn "unionLists"
40 intersectLists :: (Eq a) => [a] -> [a] -> [a]
41 intersectLists [] [] = []
42 intersectLists [] b = []
43 intersectLists a [] = []
44 intersectLists (a:as) b
45 | a `is_elem` b = a : intersectLists as b
46 | otherwise = intersectLists as b
48 #if defined(COMPILING_GHC)
49 is_elem = isIn "intersectLists"
55 Everything in the first list that is not in the second list:
57 minusList :: (Eq a) => [a] -> [a] -> [a]
58 minusList xs ys = [ x | x <- xs, x `not_elem` ys]
60 #if defined(COMPILING_GHC)
61 not_elem = isn'tIn "minusList"
68 #if ! defined(COMPILING_GHC)
70 disjointLists, intersectingLists :: Eq a => [a] -> [a] -> Bool
72 disjointLists [] bs = True
73 disjointLists (a:as) bs
75 | otherwise = disjointLists as bs
77 intersectingLists xs ys = not (disjointLists xs ys)