diff --git a/code/Angabe6.hs b/code/Angabe6.hs index 9b3517e..2ef1e7e 100644 --- a/code/Angabe6.hs +++ b/code/Angabe6.hs @@ -28,20 +28,21 @@ 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 - | otherwise = construct_row f numcol rc (cc+1) (res ++ [(f rc cc)]) + | cc > numcol = res + | otherwise = construct_row f numcol rc (cc + 1) (res ++ [(f rc cc)]) is_correct_matrix :: MatrixF -> Bool is_correct_matrix m @@ -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