-- case-Ausdrücke zusammen mit alg. Datentypen data Eintrag s i = Eintrag s i deriving (Show, Eq, Ord, Read) type Datenbank s i = [Eintrag s i] type Name = String; type Nummer = String persTelBuch, offTelBuch :: Datenbank Name Nummer persTelBuch = [Eintrag "Anne" "23247654", Eintrag "Tom" "74574547"] offTelBuch = [Eintrag "Anne" "0124675", Eintrag "Maria" "46534765"] such :: Eq s => s -> Datenbank s i -> Maybe i such x ((Eintrag sch info):db) | x == sch = Just info | otherwise = such x db such x [] = Nothing globalSuch :: Eq k => k -> [Datenbank k i] -> Maybe i globalSuch n [] = Nothing globalSuch n (db:dbs) = case (such n db) of Nothing -> globalSuch n dbs Just info -> Just info telNum :: Name -> Maybe Nummer telNum n = globalSuch n [persTelBuch, offTelBuch] test1, test2, test3 :: Maybe Nummer test1 = globalSuch "Maria" [persTelBuch, offTelBuch] test2 = globalSuch "Anne" [persTelBuch, offTelBuch] test3 = globalSuch "Anton" [persTelBuch, offTelBuch]