transposeMatrix :: Matrix -> Matrix transposeMatrix m = helper m e where (_, y) = sizeMatrix m e = emptyMatrix y helper Null new = new helper (Row row rest) new = helper rest (insertColumnRight new row)
Better one:
1 2 3
transposeMatrix :: Matrix -> Matrix transposeMatrix (Row a Null) = insertColumn (emptyMatrix (length a)) a transposeMatrix (Row a b) = insertColumn (transposeMatrix b) a
-- addRows xs ys = [xs !! i + ys !! i | i <- index] -- where -- len = length xs -- index = take len [0..]
(h)
1 2 3 4
(+#+) :: Matrix -> Matrix -> Matrix (+#+) x Null = x (+#+) Null x = x (+#+) (Row row1 rest1) (Row row2 rest2) = Row (addRows row1 row2) ((+#+) rest1 rest2)
(i)
1 2 3 4 5
(+##+) :: Matrix -> Matrix -> MaybeMatrix (+##+) x y | not (legitMatrix x) || not (legitMatrix y) = Nothing | sizeMatrix x /= sizeMatrix y = Nothing | otherwise = Just ((+#+) x y)