
On Tue, 29 Mar 2005, Johannes Waldmann wrote:
What if I don't like the Show instance?
(That seems to be a fundamental question of library design/usage.) I prefer to have show x return some string that can be pasted back into the source code (!) and gives the correct result. So, for FiniteMap I had sth. like show fm = "listToFM [ (1, True), (2, False) ]"
Since the Show and Read instances generated by the 'deriving' clause generate formatters and parsers for Haskell code it would be consistent to implement custom Show and Read instances the same way. What if not Haskell compatibility may be the criterion for the design of a Show instance? I encountered the same problem for my physical units modules. I started with a Show instance which generates strings like "2.3 km", but this can't be used as input in GHCi, again. Instead I have to write '2.3*kilo*meter' or 'read "2.3 km"'. I think that it would be better to let generate 'show' the result '2.3*kilo*meter' and I should do the conversion to traditional format using another formatter/lexer pair of routines. But how would I format numbers? Using 'show'? But 'show' formats complex numbers as 'a :+ b'. :-(