Add initial implementation for UE6
This commit is contained in:
parent
d55b40f6f7
commit
a71f57665a
@ -25,43 +25,69 @@ data MatrixF = Mf { mtyp :: Matrixtyp, mf :: Matrixfkt }
|
||||
-- Namesvereinbarung fuer den Fehlerwert
|
||||
fehler = Mf (0,0) (\_ _ -> 0) :: MatrixF
|
||||
|
||||
-- helper functions
|
||||
type Row = [Skalar]
|
||||
|
||||
construct_matrix :: MatrixF -> [Row] -> Zeile -> [Row]
|
||||
construct_matrix m res rc
|
||||
| m == fehler = []
|
||||
| otherwise =
|
||||
construct_matrix m (res ++ [(construct_row f numcol rc 1 [])]) (rc+1)
|
||||
where
|
||||
numcol = snd (mtyp m)
|
||||
f = mf m
|
||||
|
||||
|
||||
construct_row :: Matrixfkt -> Spaltenzahl -> Zeile -> Spalte -> Row -> Row
|
||||
construct_row f numcol rc cc res
|
||||
| numcol == cc = res
|
||||
| otherwise = construct_row f numcol rc (cc+1) (res ++ [(f rc cc)])
|
||||
|
||||
is_correct_matrix :: MatrixF -> Bool
|
||||
is_correct_matrix m
|
||||
| m == fehler = False
|
||||
| fst t == height && snd t == width = True
|
||||
| otherwise = False
|
||||
where
|
||||
t = mtyp m
|
||||
mtx = construct_matrix m [] 1
|
||||
height = length mtx
|
||||
width = length (head mtx)
|
||||
|
||||
|
||||
is_empty :: [Row] -> Bool
|
||||
is_empty m
|
||||
| null m = True
|
||||
| otherwise = False
|
||||
|
||||
-- Aufgabe A.1
|
||||
|
||||
instance Show MatrixF where
|
||||
show (Mf t f) = error "Nicht implementiert!"
|
||||
|
||||
|
||||
{- Knapp, aber gut nachvollziehbar geht die Instanzbildung fuer Show folgendermassen vor:
|
||||
...
|
||||
-}
|
||||
|
||||
show (Mf t f) = matrix_to_string (construct_matrix (Mf t f) [] 1) "("
|
||||
|
||||
matrix_to_string :: [Row] -> String -> String
|
||||
matrix_to_string matrix res
|
||||
| is_empty matrix = "()"
|
||||
| length m /= 0 && null ms = res ++ show m ++ ")"
|
||||
| otherwise = matrix_to_string ms (res ++ show m ++ " ")
|
||||
where
|
||||
m:ms = matrix
|
||||
|
||||
-- Aufgabe A.2
|
||||
|
||||
matrixtyp :: MatrixF -> Maybe Matrixtyp
|
||||
matrixtyp (Mf t f) = error "Nicht implementiert!"
|
||||
|
||||
|
||||
|
||||
{- Knapp, aber gut nachvollziehbar geht natrixtyp folgendermassen vor:
|
||||
...
|
||||
-}
|
||||
|
||||
|
||||
matrixtyp (Mf t f)
|
||||
| is_correct_matrix (Mf t f) == False = Nothing
|
||||
| otherwise = (Just (0,0))
|
||||
|
||||
-- Aufgabe A.4
|
||||
|
||||
instance Eq MatrixF where
|
||||
(Mf t1 f1) == (Mf t2 f2) = error "Nicht implementiert!"
|
||||
|
||||
{- Knapp, aber gut nachvollziehbar geht die Instanzbildung fuer Eq folgendermassen vor:
|
||||
...
|
||||
-}
|
||||
|
||||
|
||||
(Mf t1 f1) == (Mf t2 f2)
|
||||
| is_correct_matrix (Mf t1 f1) == False || is_correct_matrix (Mf t2 f2) = error "Gleichheit undefiniert"
|
||||
| otherwise =
|
||||
if show (Mf t1 f1) == show (Mf t2 f2) then True
|
||||
else False
|
||||
|
||||
-- Aufgabe A.5
|
||||
|
||||
|
Reference in New Issue
Block a user