[Haskell-cafe] Haskell, C and Matrix Multiplication

Pedro Vasconcelos pbv at dcc.fc.up.pt
Mon Jan 17 11:13:32 CET 2011


On Mon, 17 Jan 2011 07:45:04 +0000
Blake Rain <blake.rain at gmail.com> wrote:

> So, after drinking  some coffee and having a  smoke, I started the
> Haskell version:
> 
> [foldl (+) 0 $ zipWith (*) x y | x <- m1, y <- transpose m2]
> 

I don't think this is correct; it's type is 

	(Num a) => [[a]] -> [[a]] -> [a]

rather than the expected

	(Num a) => [[a]] -> [[a]] -> [[a]]

How about:

mult m1 m2 = [[foldl (+) 0 $ zipWith (*) x y |  y<-transpose m2] | x<-m1]

Regarding performance: did you make sure you're forcing the
evaluation of the result matrix? 

Regards,

Pedro



More information about the Haskell-Cafe mailing list