
15 Jun
2006
15 Jun
'06
9:31 a.m.
Thomas,
rotate' :: [[a]] -> [[a]] rotate' [] = [] rotate' xs = (map (head) xs ):(rotate' $ filter (not . null) $ map (tail) xs)
which seems to work just fine. While this solution is adequate (it seems to work for infinite structures as well, which is good), I originally set out to solve this problem with a fold or a mapAccum of some sort (I don't really care if it doesn't work with infinite structures). Can anyone suggest a way to write this with a fold (or tell me why it isn't a good idea)?
transpose = foldr (zipWith (:)) (repeat []) HTH, Stefan