Solution (source code)

= Solution

Use the source's `type Matrix a = [[a]]`. For its nonempty rectangular <matrices>, the number of rows and the first row's length determine the dimensions:
``
dimensions :: Matrix a -> (Int,Int)
dimensions rows = (length rows, length (head rows))

addMat :: Num a => Matrix a -> Matrix a -> Matrix a
addMat a b
  | dimensions a /= dimensions b = error "addMat: incompatible sizes"
  | otherwise = [[x + y | (x,y) <- zip r s]
                         | (r,s) <- zip a b]
``
The outer <list comprehension> pairs corresponding rows; the inner one pairs corresponding entries. Checking both dimensions before using `zip` prevents silent truncation. Thus \b[the result has entries $c_{ij}=a_{ij}+b_{ij}$], the definition of <matrix addition>. The `Num` constraint supplies the addition operation.