Add initial UE3 A.1

This commit is contained in:
Ivaylo Ivanov 2021-11-04 15:11:00 +01:00
parent 1036c68e21
commit 953219e8fc
1 changed files with 26 additions and 23 deletions

View File

@ -1,7 +1,7 @@
> module Angabe3 where
1. Vervollstaendigen Sie gemaess Angabentext!
2. Vervollständigen Sie auch die vorgegebenen Kommentaranfänge!
2. Vervollst<EFBFBD>ndigen Sie auch die vorgegebenen Kommentaranf<6E>nge!
3. Loeschen Sie keine Deklarationen aus diesem Rahmenprogramm, auch nicht die Modulanweisug!
4. Achten Sie darauf, dass `Gruppe' Leserechte fuer Ihre Abgabedatei hat!
@ -10,7 +10,7 @@
Matrizen konzeptuell als Listen von Zeilen dargestellt:
> newtype Matrix = M [Zeile]
> newtype Matrix = M [Zeile] deriving (Eq)
> fehlerwert = M [] :: Matrix
@ -20,41 +20,44 @@ Matrizen konzeptuell als Listen von Zeilen dargestellt:
Aufgabe A.1
> instance Show Matrix where
> ...
Knapp, aber gut nachvollziebar geht die Instanzdeklaration fuer Show folgendermassen vor:
> show m = matrixToString m "("
Solution:
* if the parameter matrix is an empty matrix, return "()"
* if the current row of the matrix is not empty, but the rest of the matrix is, then add the current row and close the string with ")"
* otherwise, add the current row to the result and call the function recursively with the rest of the matrix
> matrixToString :: Matrix -> String -> String
> matrixToString matrix res
> | matrix == fehlerwert = "()"
> | length m /= 0 && null ms = res ++ show m ++ ")"
> | otherwise = matrixToString restMatrix (res ++ show m ++ " ")
> where
> (M (m:ms)) = matrix
> restMatrix = (M ms)
Aufgabe A.2
> matrixtyp :: Matrix -> Matrixtyp
> ...
Knapp, aber gut nachvollziehbar geht matrixtyp folgendermassen vor:
Knapp, aber gut nachvollziehbar geht matrixtyp folgendermassen vor:
...
matrixtyp :: Matrix -> Matrixtyp
...
Aufgabe A.3
> instance Eq Matrix where
> ...
Knapp, aber gut nachvollziebar geht die Instanzdeklaration fuer Eq folgendermassen vor:
...
...
instance Eq Matrix where
...
Aufgabe A.4
> instance Num Matrix where
> ...
Knapp, aber gut nachvollziebar geht die Instanzdeklaration fuer Num folgendermassen vor:
...
Knapp, aber gut nachvollziebar geht die Instanzdeklaration fuer Num folgendermassen vor:
...
instance Num Matrix where
...