Solution (source code)

= Solution

With `dimensions` as in part (i), the alternative definition is
``
addMat :: Num a => Matrix a -> Matrix a -> Matrix a
addMat a b
  | dimensions a /= dimensions b = error "addMat: incompatible sizes"
  | otherwise = zipWith (zipWith (+)) a b
``
The inner `zipWith` adds corresponding entries; the outer one applies that row operation to corresponding rows. \b[This computes the same <matrix addition>], with the same rejection of unequal dimensions. Under the valid-input assumptions, either implementation takes $\Theta(mn)$ unit-cost arithmetic work for $m\times n$ inputs.