{- MB JUL 2020 -}
-- data type fuer Universum purer Mengen
data V = Void deriving (Eq,Show)
empty :: [V]
empty = []
naturalNumbers :: [Integer]
naturalNumbers = [0..]
evenNumbers = [ n | n <- [0..], even n]
oddNumbers = [ n | n <- [0..], odd n]
smallSquares = [ n^2 | n <- [0..999]]
union :: Eq a => [a] -> [a] -> [a]
union [] ys = ys
union (x:xs) ys = x : union xs (delete x ys)
difference :: Eq a => [a] -> [a] -> [a]
difference [] s = s
difference (x:xs) (y:ys)
| x == y = difference xs ys
| element x ys = difference xs (y: delete x ys)
| element y xs = difference ys (x: delete y xs)
| otherwise = union [x,y] (difference xs ys)
intersect :: Eq a => [a] -> [a] -> [a]
intersect [] s = []
intersect (x:xs) s | element x s = x : intersect xs s
| otherwise = intersect xs s
-- allen Mengen in einer Mengenfamilie ein Element hinzufuegen
addElement :: a -> [[a]] -> [[a]]
addElement x = map (x:)
powerSet :: [a] -> [[a]]
powerSet [] = [[]]
powerSet (x:xs) = (powerSet xs) ++ (map (x:) (powerSet xs))
generalUnion :: Eq a => [[a]] -> [a]
generalUnion [] = []
generalUnion (x:xs) = union x (generalUnion xs)
generalIntersection :: Eq a => [[a]] -> [a]
generalIntersection [] = undefined
generalIntersection (x:xs) = intersect x (generalIntersection xs)
subSet :: Eq a => [a] -> [a] -> Bool
subSet [] s = True
subSet (x:xs) s = (element x s) && (subSet xs s)
setEqual :: Eq a => [a] -> [a] -> Bool
setEqual s1 s2 = (subSet s1 s2) && (subSet s2 s1)
-- Listen der Laengen der Elementlisten
listListLength [] = [0]
listListLength (y:ys) = map length (y:ys)
-- Summe der Laengen aller Elementlisten
sumLength [] = 0
sumLength (x:xs) = sum (map length (x:xs))
delete :: Eq a => a -> [a] -> [a]
delete x [] = []
delete x (y:ys) | x == y = ys
| otherwise = y : delete x ys
element :: Eq a => a -> [a] -> Bool
element x [] = False
element x (y:ys) | x == y = True
| otherwise = element x ys