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