Skip to content

Instantly share code, notes, and snippets.

@vlas-ilya
Created December 31, 2015 06:00
Show Gist options
  • Save vlas-ilya/75bcc1d52e6374d61f0f to your computer and use it in GitHub Desktop.
Save vlas-ilya/75bcc1d52e6374d61f0f to your computer and use it in GitHub Desktop.
Транспонирование матрицы
transpose :: [[a]] -> [[a]]
transpose xs | any (\ys -> length ys == 0) xs = []
| otherwise = [h] ++ transpose t
where (h, t) = (map head xs, map tail xs)
-- *Main> transpose [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
-- [[1,4,7],[2,5,8],[3,6,9]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment