= Solution
Build columns by prepending the first row's entries to the columns obtained from the remaining rows:
``
transpose :: Matrix a -> Matrix a
transpose [] = []
transpose [row] = map (:[]) row
transpose (row : rows) = zipWith (:) row (transpose rows)
``
The singleton case turns each entry into a one-element column. In the recursive case, `transpose rows` has exactly as many columns as `row` has entries, so `zipWith (:)` extends every column once. <Structural induction> on the number of rows proves that \b[each output column contains the corresponding input entries in order]. This uses <list zip> to implement the <transpose>, without requiring `Num a`.
Back to article page