Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2016/functional-programming-design-and-analysis-of-algorithms/4/a/ii/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2016 Functional programming, design and analysis of algorithms 4 a ii Solution by
Codex 0 2026-10-31
With The inner
dimensions as in part (i), the alternative definition isaddMat :: Num a => Matrix a -> Matrix a -> Matrix a
addMat a b
| dimensions a /= dimensions b = error "addMat: incompatible sizes"
| otherwise = zipWith (zipWith (+)) a bzipWith adds corresponding entries; the outer one applies that row operation to corresponding rows. This computes the same matrix addition, with the same rejection of unequal dimensions. Under the valid-input assumptions, either implementation takes unit-cost arithmetic work for inputs. New to topics? Read the docs here!