
5 Jun
2019
5 Jun
'19
10:18 a.m.
Shouldn't it be laws that "show" must be injective and "read" must be surjective? My opinion (and that of many others) is that
* Show and Read should be used only for debugging purposes or things that directly relate to Haskell data types when written as literals * whenever possible, use only the GHC-derived instances for those * for all other use cases, different explicit parsers or pretty-printers should be used. The GHC-derived instances also automatically make your desired laws mostly hold. Injectivity seems a bit off, given that e.g. (read "3" :: Int) == (read " 3 " :: Int) so whitespace stripping, parentheses etc. allow different inputs to map to same outputs. Niklas