diff --git a/code/Angabe5.hs b/code/Angabe5.hs index 8da21b7..d45e268 100644 --- a/code/Angabe5.hs +++ b/code/Angabe5.hs @@ -97,6 +97,11 @@ instance Num Zahlraum_0_10 where (-) n n' = diff_r n n' (*) n n' = mult_r n n' fromInteger n = nat_to_roman (fromInteger n) + abs n = n + signum n + | n == F = F + | n == N = N + | otherwise = I add_r :: Zahlraum_0_10 -> Zahlraum_0_10 -> Zahlraum_0_10 add_r n n' @@ -127,12 +132,22 @@ mult_r n n' -- Aufgabe A.2 --- instance Eq Funktion where --- ... +instance Eq Funktion where + (==) f f' = (show f) == (show f') --- instance Show Funktion where --- ... +instance Show Funktion where + show f = + let + result = drop 1 (show (build_pairs f N)) + in + "{" ++ take ((length result) -1) result ++ "}" +build_pairs :: Funktion -> Zahlraum_0_10 -> [(Zahlraum_0_10, Zahlraum_0_10)] +build_pairs fkt arg + | arg == F && z == F = [(F, F)] + | otherwise = (arg, z) : (build_pairs fkt (arg + I)) + where + z = (f fkt) arg -- Aufgabe A.3