Add UE5 A.1
This commit is contained in:
parent
6b7ca28fe0
commit
711a2a1104
163
code/Angabe5.hs
163
code/Angabe5.hs
@ -52,121 +52,132 @@ data PH_ElemTyp a b c d e = A a | B b | C c | D d | E e deriving (Eq,Show)
|
||||
data PH_ElemTyp' q r s = Q q | R r | S s deriving (Eq,Show)
|
||||
|
||||
|
||||
-- Simple helper functions
|
||||
roman_to_nat :: Zahlraum_0_10 -> Nat0
|
||||
roman_to_nat N = 0
|
||||
roman_to_nat I = 1
|
||||
roman_to_nat II = 2
|
||||
roman_to_nat III = 3
|
||||
roman_to_nat IV = 4
|
||||
roman_to_nat V = 5
|
||||
roman_to_nat VI = 6
|
||||
roman_to_nat VII = 7
|
||||
roman_to_nat VIII = 8
|
||||
roman_to_nat IX = 9
|
||||
roman_to_nat X = 10
|
||||
roman_to_nat F = -1
|
||||
|
||||
nat_to_roman :: Nat0 -> Zahlraum_0_10
|
||||
nat_to_roman 0 = N
|
||||
nat_to_roman 1 = I
|
||||
nat_to_roman 2 = II
|
||||
nat_to_roman 3 = III
|
||||
nat_to_roman 4 = IV
|
||||
nat_to_roman 5 = V
|
||||
nat_to_roman 6 = VI
|
||||
nat_to_roman 7 = VII
|
||||
nat_to_roman 8 = VIII
|
||||
nat_to_roman 9 = IX
|
||||
nat_to_roman 10 = X
|
||||
nat_to_roman n
|
||||
| n > 10 = F
|
||||
| n < 0 = F
|
||||
| otherwise = error "Could not recognize input" -- this should not happen
|
||||
|
||||
is_correct_num :: Zahlraum_0_10 -> Bool
|
||||
is_correct_num n =
|
||||
case n of
|
||||
F -> False
|
||||
_ -> True
|
||||
|
||||
-- Aufgabe A.1
|
||||
|
||||
instance Num Zahlraum_0_10 where
|
||||
...
|
||||
|
||||
{- Knapp, aber gut nachvollziehbar geht die Instanzbildung fuer Num folgendermassen vor:
|
||||
...
|
||||
-}
|
||||
(+) n n' = add_r n n'
|
||||
(-) n n' = diff_r n n'
|
||||
(*) n n' = mult_r n n'
|
||||
fromInteger n = nat_to_roman (fromInteger n)
|
||||
|
||||
add_r :: Zahlraum_0_10 -> Zahlraum_0_10 -> Zahlraum_0_10
|
||||
add_r n n'
|
||||
| is_correct_num n == False || is_correct_num n' == False = F
|
||||
| otherwise = nat_to_roman sum_r
|
||||
where
|
||||
a = roman_to_nat n
|
||||
b = roman_to_nat n'
|
||||
sum_r = a + b
|
||||
|
||||
diff_r :: Zahlraum_0_10 -> Zahlraum_0_10 -> Zahlraum_0_10
|
||||
diff_r n n'
|
||||
| is_correct_num n == False || is_correct_num n' == False = F
|
||||
| otherwise = nat_to_roman dif_r
|
||||
where
|
||||
a = roman_to_nat n
|
||||
b = roman_to_nat n'
|
||||
dif_r = a - b
|
||||
|
||||
mult_r :: Zahlraum_0_10 -> Zahlraum_0_10 -> Zahlraum_0_10
|
||||
mult_r n n'
|
||||
| is_correct_num n == False || is_correct_num n' == False = F
|
||||
| otherwise = nat_to_roman prod_r
|
||||
where
|
||||
a = roman_to_nat n
|
||||
b = roman_to_nat n'
|
||||
prod_r = a * b
|
||||
|
||||
-- Aufgabe A.2
|
||||
|
||||
instance Eq Funktion where
|
||||
...
|
||||
|
||||
instance Show Funktion where
|
||||
...
|
||||
|
||||
{- Knapp, aber gut nachvollziehbar gehen die beiden Instanzbildungen fuer
|
||||
Eq und Show folgendermassen vor:
|
||||
...
|
||||
-}
|
||||
|
||||
-- instance Eq Funktion where
|
||||
-- ...
|
||||
|
||||
-- instance Show Funktion where
|
||||
-- ...
|
||||
|
||||
|
||||
-- Aufgabe A.3
|
||||
|
||||
instance Menge_von Int where
|
||||
...
|
||||
|
||||
instance Menge_von Zahlraum_0_10 where
|
||||
...
|
||||
|
||||
instance Menge_von Funktion where
|
||||
...
|
||||
|
||||
|
||||
{- Knapp, aber gut nachvollziehbar gehen die drei Instanzbildungen fuer
|
||||
Menge_von folgendermassen vor:
|
||||
...
|
||||
-}
|
||||
-- instance Menge_von Int 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
|
||||
...
|
||||
|
||||
{- Knapp, aber gut nachvollziehbar gehen die beiden Instanzbildungen fuer
|
||||
Menge_von folgendermassen vor:
|
||||
...
|
||||
-}
|
||||
-- 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
|
||||
...
|
||||
|
||||
{- Knapp, aber gut nachvollziehbar gehen die beiden Instanzbildungen fuer
|
||||
Eq und Show folgendermassen vor:
|
||||
...
|
||||
-}
|
||||
|
||||
-- instance Eq a => Eq (ElemTyp a) where
|
||||
-- ...
|
||||
|
||||
-- instance Show a => Show (ElemTyp a) where
|
||||
-- ...
|
||||
|
||||
|
||||
-- Aufgabe A.6
|
||||
|
||||
instance Eq a => Menge_von (ElemTyp a) where
|
||||
...
|
||||
|
||||
{- Knapp, aber gut nachvollziehbar geht die Instanzbildung fuer
|
||||
Menge_von folgendermassen vor:
|
||||
...
|
||||
-}
|
||||
|
||||
-- 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
|
||||
...
|
||||
|
||||
{- Knapp, aber gut nachvollziehbar geht die Instanzbildung fuer
|
||||
Menge_von folgendermassen vor:
|
||||
...
|
||||
-}
|
||||
|
||||
|
||||
-- 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 ...
|
||||
|
||||
|
||||
{- Knapp, aber gut nachvollziehbar geht die Instanzbildung fuer
|
||||
Menge_von folgendermassen vor:
|
||||
...
|
||||
-}
|
||||
|
||||
-- instance (Eq p,Eq q,Eq r) => Menge_von (PH_ElemTyp' p q r) where ...
|
||||
|
||||
|
Reference in New Issue
Block a user