calcCell Int Int Int calcCell sum minimum length x-1 length y-1 getRow

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
calcCell::[Int]->[Int]->Int
calcCell x y = sum [ (x !! i ) * (y !! i ) | i<-[0.. minimum[length x-1,length y-1 ] ] ]
getRow::[[Int]]->Int->[Int]
getRow mtrx i = if (i < length mtrx) then mtrx !! i else []
getCol::[[Int]]->Int->[Int]
getCol mtrx j = [ mtrx !! i!!j | i<-[0..length (mtrx) -1] ]
matMult :: [[Int]]->[[Int]]->[[Int]]
matMult xm ym = [
[ (calcCell (getRow xm j) (getCol ym i)) | j<-[0..(length (ym!!0) -1)]]
| i<-[0..length xm-1]
]