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