Add UE5 A.3
This commit is contained in:
parent
7033fc1258
commit
c1208da5b9
@ -1,4 +1,5 @@
|
||||
module Angabe5 where
|
||||
import Data.List
|
||||
|
||||
{- 1. Vervollstaendigen Sie gemaess Angabentext!
|
||||
2. Vervollständigen Sie auch die vorgegebenen Kommentaranfänge!
|
||||
@ -26,13 +27,23 @@ class Eq a => Menge_von a where
|
||||
|
||||
-- Protoimplementierungen
|
||||
leer = []
|
||||
vereinige xs ys = xs ++ ys
|
||||
ist_teilmenge xs ys = ist_obermenge ys xs
|
||||
vereinige xs ys = clear_duplicates (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_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
|
||||
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:
|
||||
|
||||
@ -151,48 +162,33 @@ build_pairs fkt arg
|
||||
|
||||
-- Aufgabe A.3
|
||||
|
||||
-- instance Menge_von Int where
|
||||
-- ...
|
||||
instance Menge_von Int where
|
||||
|
||||
-- instance Menge_von Zahlraum_0_10 where
|
||||
-- ...
|
||||
|
||||
-- instance Menge_von Funktion where
|
||||
-- ...
|
||||
instance Menge_von Zahlraum_0_10 where
|
||||
|
||||
instance Menge_von Funktion where
|
||||
|
||||
-- Aufgabe A.4
|
||||
|
||||
-- instance (Eq a,Eq b) => Menge_von (Paar a b) where
|
||||
-- ...
|
||||
|
||||
-- instance Eq a => Menge_von (Baum a) where
|
||||
-- ...
|
||||
instance (Eq a,Eq b) => Menge_von (Paar a b) where
|
||||
|
||||
instance Eq a => Menge_von (Baum a) where
|
||||
|
||||
-- Aufgabe A.5
|
||||
|
||||
-- instance Eq a => Eq (ElemTyp a) where
|
||||
-- ...
|
||||
|
||||
-- instance Show a => Show (ElemTyp a) where
|
||||
-- ...
|
||||
instance Eq a => Eq (ElemTyp a) where
|
||||
(==) (ET a) (ET b) = a == b
|
||||
|
||||
instance Show a => Show (ElemTyp a) where
|
||||
|
||||
-- Aufgabe A.6
|
||||
|
||||
-- instance Eq a => Menge_von (ElemTyp a) where
|
||||
-- ...
|
||||
|
||||
|
||||
instance Eq a => Menge_von (ElemTyp a) where
|
||||
|
||||
-- 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
|
||||
|
||||
-- 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
|
||||
|
@ -78,10 +78,10 @@ spec =
|
||||
funktion_tests,
|
||||
menge_von_int_tests,
|
||||
menge_von_zahlraum_0_10_tests,
|
||||
menge_von_funktion_tests,
|
||||
menge_von_ElemTyp_tests,
|
||||
ph_elemtyp_tests,
|
||||
ph_elemtyp'_tests
|
||||
menge_von_funktion_tests
|
||||
-- menge_von_ElemTyp_tests,
|
||||
-- ph_elemtyp_tests,
|
||||
-- ph_elemtyp'_tests
|
||||
]
|
||||
|
||||
zahlraum_0_10_tests :: TestTree
|
||||
|
Reference in New Issue
Block a user