Reputation: 65
I am trying to define a function to multiply a list of lists (Matrix) in Haskell.
So far, I have been able to define a function to multiply two lists, though I'm not sure about list of lists. Could anyone lend a hand?
mult m1 m2 = zipWith (*) m1 m2
Upvotes: 1
Views: 198
Reputation: 476557
You can apply the same trick for each two rows of the matrix, so:
elementwiseMult :: Num a => [[a]] -> [[a]] -> [[a]]
elementwiseMult = zipWith mult
with mult
the function you defined to multiple two rows together.
Upvotes: 3