High-quality splittable pseudorandom number generator
#8"Show" instance for Hex
We just discovered that the show instance for Hex is buggy. Consider the following program:
> data B = B TFGen String deriving Show
> B tf "f"
B (TFGenR 000000025E37A9D3000000000003D090000000000000DE920000005C5B22D280 0 2 2 0) "F"
As you can see, the "f" is printed in upper-case. This is because the implementation of showsPrec violates the law
showsPrec d x r ++ s == showsPrec d x (r ++ s)
(see [1]), as "map toUpper" is also applied to the argument string. I would argue that the simplest fix is to implement "show" instead.
Best regards, Lars Noschinski
Issue Bundle- description updated
- description updated
Added patch.
Hi Lars, Thanks for spotting this and for the patch! I pushed a slightly different patch that should also fix the issue. Please let me know if it looks good for you. I would like to hold back with a bug-fix release to accumulate more changes in it. If you would like to have this released sooner, please let me know.
Best, MichaB
- status set to closed
Looks good. I believe you don't gain much from using a DList-style showHex', as concat should be as efficient as that, but this is clearly the more minmal change (and arguably, toUpper really belongs into the showHex' function).
This is just a cosmetic issue for us, so waiting to release this is fine. Thanks for the quick reaction though, I can remove this from my mental "open bugs" lists :)
Best regards, Lars
I just ran into this issue. Could you please release a fixed version on Hackage?