
13 Nov
2005
13 Nov
'05
12:04 p.m.
On Sun, Nov 13, 2005 at 01:51:22PM +0000, Dominic Steinitz wrote:
I often find myself wanting to print out hex values as a string.
Me too. I have a functions that formats the data in a similar way that the xxd program does.
I couldn't find a library function so I came up with this. Is it worth putting in a library?
Sure.
Thoughts?
I haven't thought about producing a Doc - good idea.
split :: Int -> [a] -> [[a]] split n xs = unfoldr (g n) xs where g :: Int -> [a] -> Maybe ([a],[a]) g n y | length y == 0 = Nothing | otherwise = Just (splitAt n y)
The first guard, (length y == 0), seems a bit expensive - the whole thing will have a quadratic time and can evaluate the input list too eagerly. Best regards Tomasz