Fix some helper functions in UE6

This commit is contained in:
Ivaylo Ivanov 2021-11-23 17:59:22 +01:00
parent a71f57665a
commit e55d7c4615

View File

@ -28,19 +28,20 @@ fehler = Mf (0,0) (\_ _ -> 0) :: MatrixF
-- helper functions
type Row = [Skalar]
construct_matrix :: MatrixF -> [Row] -> Zeile -> [Row]
construct_matrix m res rc
construct_matrix :: MatrixF -> Zeile -> [Row] -> [Row]
construct_matrix m rc res
| m == fehler = []
| rc > numrow = res
| otherwise =
construct_matrix m (res ++ [(construct_row f numcol rc 1 [])]) (rc+1)
construct_matrix m (rc + 1) (res ++ [(construct_row f numcol rc 1 [])])
where
numcol = snd (mtyp m)
numrow = fst (mtyp m)
f = mf m
construct_row :: Matrixfkt -> Spaltenzahl -> Zeile -> Spalte -> Row -> Row
construct_row f numcol rc cc res
| numcol == cc = res
| cc > numcol = res
| otherwise = construct_row f numcol rc (cc + 1) (res ++ [(f rc cc)])
is_correct_matrix :: MatrixF -> Bool
@ -50,11 +51,10 @@ is_correct_matrix m
| otherwise = False
where
t = mtyp m
mtx = construct_matrix m [] 1
mtx = construct_matrix m 1 []
height = length mtx
width = length (head mtx)
is_empty :: [Row] -> Bool
is_empty m
| null m = True
@ -63,7 +63,7 @@ is_empty m
-- Aufgabe A.1
instance Show MatrixF where
show (Mf t f) = matrix_to_string (construct_matrix (Mf t f) [] 1) "("
show (Mf t f) = matrix_to_string (construct_matrix (Mf t f) 1 []) "("
matrix_to_string :: [Row] -> String -> String
matrix_to_string matrix res