From 09b8148fa626793021beff8b21b6c3d3b1594f00 Mon Sep 17 00:00:00 2001 From: Ivaylo Ivanov Date: Thu, 4 Nov 2021 16:22:45 +0100 Subject: [PATCH] Add UE3 A.2 --- code/Angabe3.lhs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/code/Angabe3.lhs b/code/Angabe3.lhs index 25fb941..cc6c6f2 100644 --- a/code/Angabe3.lhs +++ b/code/Angabe3.lhs @@ -38,12 +38,28 @@ Solution: Aufgabe A.2 -Knapp, aber gut nachvollziehbar geht matrixtyp folgendermassen vor: -... +Solution: + * if the parameter is an empty matrix, then return KeineMatrix + * check if the parameter is an NM matrix by obtaining the length of the first row and comparing it with each consequitive one. If there is a mismatch, then the matrix is not a NM matrix + * if the parameter is an NM matrix, return the pair (height, width) -matrixtyp :: Matrix -> Matrixtyp - ... +> matrixtyp :: Matrix -> Matrixtyp +> matrixtyp m +> | m == fehlerwert = KeineMatrix +> | isCorrectMatrix m 0 == False = KeineMatrix +> | otherwise = getMatrixType m +> isCorrectMatrix :: Matrix -> Int -> Bool +> isCorrectMatrix matrix n +> | matrix == fehlerwert = True +> | n == 0 && length m /= 0 = isCorrectMatrix matrix (length m) +> | n == length m = isCorrectMatrix (M ms) n +> | otherwise = False +> where +> (M (m:ms)) = matrix + +> getMatrixType :: Matrix -> Matrixtyp +> getMatrixType (M (m:ms)) = (Mat (length (m:ms), length m)) Aufgabe A.3