[Haskell-beginners] Why is the the transpose function in Data.List more complicated?

KC kc1956 at gmail.com
Sat Aug 4 01:34:41 CEST 2012


Transpose in Data.List is the following:

transpose               :: [[a]] -> [[a]]
transpose []             = []
transpose ([]   : xss)   = transpose xss
transpose ((x:xs) : xss) = (x : [h | (h:_) <- xss]) : transpose (xs :
[ t | (_:t) <- xss])


Yet this seems to work.

transp :: [[b]] -> [[b]]
transp ([]:_)   = []
transp rows     = map head rows : transp (map tail rows)


Why is the the transpose function in Data.List more complicated?

--
--
Regards,
KC



More information about the Beginners mailing list