Show with Strings
Derek Elkins
ddarius@hotpop.com
Sun, 3 Aug 2003 20:29:17 -0400
On Mon, 4 Aug 2003 10:01:50 +0000
"Thomas L. Bevan" <thomas_bevan@toll.com.au> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Is there any reason why
> show :: String -> String
> is not equivalent to 'id' ?
Because I believe the intent (the Report may make some mention of this)
is that read . show should be id. Either way, you aren't strongly
exercising the function. What about show "\"" which is """ or show
"\0\r\n" and other such examples? This wouldn't be the right result for
many uses.
> At the moment,
>
> show "one" = "\"one\""
>
> which leads to problems because it often
> requires String to be treated as a special case,
> rather than just a member of Show.
>
> Tom
Having show :: String -> String be id would be making a special case the
other way. Perhaps the sensible thing to do is make your own class say
Display, e.g.
class Display a where
display :: a -> String
This would be a class for displaying values rather than something more
akin to textual serialization that Show is. You can go further and make
a pretty printing class, or a less flexibly, but a little more
conveniently is
class Show a => Display a where
display :: a -> String
display = show
So that you can just have,
instance Display Bool
instance Display Int, etc.
with
instance Display String where
display = id