
3 Aug
2012
3 Aug
'12
8:05 p.m.
Hi KC,
transp :: [[b]] -> [[b]] transp ([]:_) = [] transp rows = map head rows : transp (map tail rows)
Why is the the transpose function in Data.List more complicated?
In the Data.List version, the list comprehension syntax quietly filters out items that fail to pattern-match (empty lists). Therefore the transpose in Data.List does not generate a pattern-match exception when you give it lists of different lengths: transpose [[1], [], [3]] == [[1,3]] The Data.List version also returns an empty list if the input is an empty list, whereas your version returns an infinite list of empty lists. -Greg