Hi,
This one works for all 3 examples you gave:
diag = concat . takeWhile (not.null)
. foldr1 (flip $ zipWith (flip (++)) . ([]:))
. map ((++ repeat []) . map (:[]))
or, using Matt Hellige's pointless fun
http://matt.immute.net/content/pointless-fun
diag = foldr1 (zipWith (++) $. id ~> ([]:) ~> id)
$. map (++ repeat []) ~> takeWhile (not.null)
$. (map.map) (:[]) ~> concat
I think the second one is quite readable, thanks to Matt's notation.
The essential part is up front, and the pre- and post-transformations
that belong to each other can be grouped.
greetings,
--
Sjoerd Visscher
[email protected]
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe