Skip to content

Instantly share code, notes, and snippets.

@adamczykm
Created November 27, 2015 21:25
Show Gist options
  • Save adamczykm/00136e67c96295e5e2b4 to your computer and use it in GitHub Desktop.
Save adamczykm/00136e67c96295e5e2b4 to your computer and use it in GitHub Desktop.
import GHC.Show (intToDigit)
-- | Fast hex representation of Word8
showHex :: Word8 -> ShowS
showHex n0 = showIt (1 :: Int) (quotRem n0 16)
where
showIt x (n,d) r = seq c $ -- stricter than necessary
case x of
0 -> r'
_ -> showIt (x-1) (quotRem n 16) r'
where
c = intToDigit (fromIntegral d)
r' = c : r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment