Zvonimir
Zvonimir

Reputation: 65

Multiply list of lists Haskell

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

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

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

Related Questions