
18 Mar
2006
18 Mar
'06
5:48 a.m.
All, I finally got around to putting a "hexdump" function into a module. Any suggestions as to where it should live in the hierarchy? Dominic. module Hex( ppHex ) where import Data.List import Codec.Utils import Numeric import Text.PrettyPrint split :: Int -> [a] -> [[a]] split n xs = unfoldr (g n) xs g :: Int -> [a] -> Maybe ([a],[a]) g n [] = Nothing g n y = Just (splitAt n y) sh x | x < 16 = '0':(showHex x "") | otherwise = showHex x "" type OctetsPerLine = Int ppHex :: OctetsPerLine -> [Octet] -> Doc ppHex n = vcat . map hcat . map (intersperse colon) . map (map (text . sh)) . split n