Build columns by prepending the first row's entries to the columns obtained from the remaining rows:The singleton case turns each entry into a one-element column. In the recursive case,
transpose :: Matrix a -> Matrix a
transpose [] = []
transpose [row] = map (:[]) row
transpose (row : rows) = zipWith (:) row (transpose rows)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 each output column contains the corresponding input entries in order. This uses list zip to implement the transpose, without requiring Num a. Articles by others on the same topic
There are currently no matching articles.