Add correct error checks

This commit is contained in:
Ivaylo Ivanov 2021-11-18 18:39:32 +01:00
parent d288b49fcf
commit 76e37d28d9

View File

@ -27,14 +27,14 @@ class Eq a => Menge_von a where
-- Protoimplementierungen
leer = []
vereinige xs ys = xs ++ ys
schneide xs ys = xs \\ (xs \\ ys)
ziehe_ab xs ys = xs \\ (intersectBy (==) xs ys)
ist_teilmenge xs ys = (length (ziehe_ab xs ys) == 0)
vereinige xs ys = if (has_duplicates xs) || (has_duplicates ys) then error "Fehler" else clear_duplicates (xs ++ ys)
schneide xs ys = if (has_duplicates xs) || (has_duplicates ys) then error "Fehler" else xs \\ (xs \\ ys)
ziehe_ab xs ys = if (has_duplicates xs) || (has_duplicates ys) then error "Fehler" else xs \\ (intersectBy (==) xs ys)
ist_teilmenge xs ys = if (has_duplicates xs) || (has_duplicates ys) then error "Fehler" else (length (ziehe_ab xs ys) == 0)
ist_obermenge xs ys = ist_teilmenge ys xs
ist_element x xs = anzahl x xs >= 1
anzahl x xs = if (has_duplicates xs) then error "Fehler" else (length . filter (== x)) xs
ist_leer xs = xs == leer
ist_leer xs = if (has_duplicates xs) then error "Fehler" else xs == leer
sind_gleich xs ys = ist_teilmenge xs ys && ist_teilmenge ys xs
-- Weitere Typen:
@ -163,13 +163,10 @@ build_pairs fkt arg
-- Aufgabe A.3
instance Menge_von Int where
vereinige xs ys = clear_duplicates (xs ++ ys)
instance Menge_von Zahlraum_0_10 where
vereinige xs ys = clear_duplicates (xs ++ ys)
instance Menge_von Funktion where
vereinige xs ys = clear_duplicates (xs ++ ys)
-- Aufgabe A.4
@ -188,13 +185,25 @@ instance Show a => Show (ElemTyp a) where
-- Aufgabe A.6
instance Eq a => Menge_von (ElemTyp a) where
anzahl x xs = (length . filter (== x)) xs
anzahl x xs = (length . filter (== x)) xs
vereinige xs ys = xs ++ ys
schneide xs ys = xs \\ (xs \\ ys)
ziehe_ab xs ys = xs \\ (intersectBy (==) xs ys)
ist_teilmenge xs ys = (length (ziehe_ab xs ys) == 0)
ist_obermenge xs ys = ist_teilmenge ys xs
ist_leer xs = xs == leer
-- Aufgabe A.7
instance (Eq a,Eq b,Eq c,Eq d,Eq e) => Menge_von (PH_ElemTyp a b c d e) where
vereinige xs ys = clear_duplicates (xs ++ ys)
-- Aufgabe A.8
instance (Eq p,Eq q,Eq r) => Menge_von (PH_ElemTyp' p q r) where
anzahl x xs = (length . filter (== x)) xs
vereinige xs ys = xs ++ ys
schneide xs ys = xs \\ (xs \\ ys)
ziehe_ab xs ys = xs \\ (intersectBy (==) xs ys)
ist_teilmenge xs ys = (length (ziehe_ab xs ys) == 0)
ist_obermenge xs ys = ist_teilmenge ys xs
ist_leer xs = xs == leer