Hex Values

Tomasz Zielonka tomasz.zielonka at gmail.com
Sun Nov 13 12:04:59 EST 2005


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


More information about the Libraries mailing list