Understanding this matrix transposition function in Haskell
Posted
by dmindreader
on Stack Overflow
See other posts from Stack Overflow
or by dmindreader
Published on 2010-04-05T14:40:11Z
Indexed on
2010/04/05
14:43 UTC
Read the original article
Hit count: 297
haskell
This matrix transposition function works, but I'm trying to understand its step by step execurtion and I don't get it.
transpose:: [[a]]->[[a]]
transpose ([]:_) = []
transpose x = (map head x) : transpose (map tail x)
with
transpose [[1,2,3],[4,5,6],[7,8,9]]
it returns:
[[1,4,7],[2,5,8],[3,6,9]]
I don't get how the concatenation operator is working with map. It is concatenating each head of x in the same function call? How?
© Stack Overflow or respective owner