[Haskell-cafe] Simple matrix

Twan van Laarhoven twanvl at gmail.com
Wed Jun 21 16:57:32 EDT 2006


Jared Updike wrote:

 > Wouldn't you want the expression
 >
 > [[1,0],[0,2]] + 10
 > to yield
 > [[11,10],[10,12]]

You could handle this as a special case in (+) and (*), but this is kind 
of a hack. Something like:
 > (+) [[x]]  y   = map (map (x+)) y
 > (+)   x  [[y]] = map (map (+y)) x
 > (+)   x    y   = zipWith (zipWith (+)) x y

Twan


More information about the Haskell-Cafe mailing list