Add (almost) correct function implemenations for all types in UE5
This commit is contained in:
parent
c1208da5b9
commit
d288b49fcf
@ -27,7 +27,7 @@ class Eq a => Menge_von a where
|
|||||||
|
|
||||||
-- Protoimplementierungen
|
-- Protoimplementierungen
|
||||||
leer = []
|
leer = []
|
||||||
vereinige xs ys = clear_duplicates (xs ++ ys)
|
vereinige xs ys = xs ++ ys
|
||||||
schneide xs ys = xs \\ (xs \\ ys)
|
schneide xs ys = xs \\ (xs \\ ys)
|
||||||
ziehe_ab xs ys = xs \\ (intersectBy (==) xs ys)
|
ziehe_ab xs ys = xs \\ (intersectBy (==) xs ys)
|
||||||
ist_teilmenge xs ys = (length (ziehe_ab xs ys) == 0)
|
ist_teilmenge xs ys = (length (ziehe_ab xs ys) == 0)
|
||||||
@ -37,14 +37,6 @@ class Eq a => Menge_von a where
|
|||||||
ist_leer xs = xs == leer
|
ist_leer xs = 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
|
||||||
|
|
||||||
clear_duplicates :: Eq a => [a] -> [a]
|
|
||||||
clear_duplicates [] = []
|
|
||||||
clear_duplicates (x:xs) = x : filter (/= x) (clear_duplicates xs)
|
|
||||||
|
|
||||||
has_duplicates:: Eq a => [a] -> Bool
|
|
||||||
has_duplicates [] = False
|
|
||||||
has_duplicates (x:xs) = if x `elem` xs then True else has_duplicates xs
|
|
||||||
|
|
||||||
-- Weitere Typen:
|
-- Weitere Typen:
|
||||||
|
|
||||||
newtype Paar a b = P (a,b) deriving (Eq,Show)
|
newtype Paar a b = P (a,b) deriving (Eq,Show)
|
||||||
@ -101,6 +93,14 @@ is_correct_num n =
|
|||||||
F -> False
|
F -> False
|
||||||
_ -> True
|
_ -> True
|
||||||
|
|
||||||
|
clear_duplicates :: Eq a => [a] -> [a]
|
||||||
|
clear_duplicates [] = []
|
||||||
|
clear_duplicates (x:xs) = x : filter (/= x) (clear_duplicates xs)
|
||||||
|
|
||||||
|
has_duplicates:: Eq a => [a] -> Bool
|
||||||
|
has_duplicates [] = False
|
||||||
|
has_duplicates (x:xs) = if x `elem` xs then True else has_duplicates xs
|
||||||
|
|
||||||
-- Aufgabe A.1
|
-- Aufgabe A.1
|
||||||
|
|
||||||
instance Num Zahlraum_0_10 where
|
instance Num Zahlraum_0_10 where
|
||||||
@ -163,10 +163,13 @@ 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
|
||||||
|
|
||||||
@ -180,14 +183,17 @@ instance Eq a => Eq (ElemTyp a) where
|
|||||||
(==) (ET a) (ET b) = a == b
|
(==) (ET a) (ET b) = a == b
|
||||||
|
|
||||||
instance Show a => Show (ElemTyp a) where
|
instance Show a => Show (ElemTyp a) where
|
||||||
|
show (ET a) = show a
|
||||||
|
|
||||||
-- Aufgabe A.6
|
-- Aufgabe A.6
|
||||||
|
|
||||||
instance Eq a => Menge_von (ElemTyp a) where
|
instance Eq a => Menge_von (ElemTyp a) where
|
||||||
|
anzahl x xs = (length . filter (== x)) xs
|
||||||
|
|
||||||
-- 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
|
||||||
|
|
||||||
|
@ -78,10 +78,10 @@ spec =
|
|||||||
funktion_tests,
|
funktion_tests,
|
||||||
menge_von_int_tests,
|
menge_von_int_tests,
|
||||||
menge_von_zahlraum_0_10_tests,
|
menge_von_zahlraum_0_10_tests,
|
||||||
menge_von_funktion_tests
|
menge_von_funktion_tests,
|
||||||
-- menge_von_ElemTyp_tests,
|
menge_von_ElemTyp_tests,
|
||||||
-- ph_elemtyp_tests,
|
ph_elemtyp_tests,
|
||||||
-- ph_elemtyp'_tests
|
ph_elemtyp'_tests
|
||||||
]
|
]
|
||||||
|
|
||||||
zahlraum_0_10_tests :: TestTree
|
zahlraum_0_10_tests :: TestTree
|
||||||
|
Reference in New Issue
Block a user