
4 Nov
2009
4 Nov
'09
1:01 p.m.
The code by Twan can be reduced to this: diagN = concat . foldr f [[[]]] f :: [a] -> [[[a]]] -> [[[a]]] f xs ys = foldr (g ys) [] xs g :: [[[a]]] -> a -> [[[a]]] -> [[[a]]] g ys x xs = merge (map (map (x:)) ys) ([] : xs) merge :: [[a]] -> [[a]] -> [[a]] merge [] ys = ys merge xs [] = xs merge (x:xs) (y:ys) = (x++y) : merge xs ys But my feeling is that this can still be simplified further. Or at least refactored so it is clear what actually is going on! -- Sjoerd Visscher sjoerd@w3future.com