我有一个问题要展示一个矩阵。 这是程序输出的模样。 我有点卡住了 。
unfoldMatrix :: [ [a] ] -> [a]
Main> unfoldMatrix [[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[10, 11, 12]]
[1,4,7,10,11,12,9,6,3,2,5,8]
我的代码有效,但它的输出是这种格式的
[[1,4,7]、[8,9]、[6,3]、[2]、[5]、[ ]
任何想法 如何改变代码 工作想要?
transpose2:: [[a]]->[[a]]
transpose2 ([]:_) = []
transpose2 x = (map head x) : transpose2 (map tail x)
unfoldMatrix:: [[a]]->[[a]]
unfoldMatrix ([]:_) = []
unfoldMatrix x =(map head x):unfoldMatrix(tail2(x))
rotate90 :: [ [ a ] ] -> [ [ a ] ]
rotate90 = (map reverse).transpose2
tail2:: [[a]]->[[a]]
tail2 = (tail).rotate90