From 7033fc125825c1153cb98ac2638300f06a56a9ec Mon Sep 17 00:00:00 2001 From: Ivaylo Ivanov Date: Thu, 18 Nov 2021 17:05:21 +0100 Subject: [PATCH] Add UE5 A.2 --- code/Angabe5.hs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) 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