--innerProduct :: [Int] -> [Int] -> Int dotProduct [] [] = 0 dotProduct (x:xs) (y:ys) = x * y + dotProduct xs ys --oneRow row [[], []] = [] oneRow row mat@(x:xs) = if null x then [] else dotProduct row (map head mat) : oneRow row (map tail mat) almostMatrixMult mat1 mat2 = if null mat1 then [[]] else oneRow (head mat1) mat2 : almostMatrixMult (tail mat1) mat2 matrixMult mat1 mat2 = [a | a <- almostMatrixMult mat1 mat2, not $ null a] dropNth xs n = map fst $ filter ((n/=) . snd) $ zip xs [1..] minor mat i = dropNth (map tail mat) i cofac mat i = ((-1) ^ (i+1)) * det (minor mat i) expFac mat i = head (mat!!(i-1)) * cofac mat i det [[a, b], [c, d]] = a * d - b * c det mat = helper mat 1 where helper mat i = if i >= length mat then expFac mat i else expFac mat i + helper mat (i+1)