[Haskell-cafe] Simple matrix

Ross Paterson ross at soi.city.ac.uk
Thu Jun 22 06:56:01 EDT 2006


On Thu, Jun 22, 2006 at 11:57:37AM +0200, Udo Stenzel wrote:
> instance Num a => Num [[a]] where
> 	(+) = zipWith (zipWith (+))
> 	(-) = zipWith (zipWith (-))
> 	negate = map (map negate)
> 	fromInteger x = fix (((x : repeat 0) :) . map (0:))
> 	m * n = [ [ sum $ zipWith (*) v w | w <- transpose n ] | v <- m ] 

or perhaps

	fromInteger x = iterate (0:) (x : repeat 0)



More information about the Haskell-Cafe mailing list