
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Is there any reason why show :: String -> String is not equivalent to 'id' ? 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 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/Li8QYha8TWXIQwoRApCgAJ49iJcOuf88WTIKVJWBkHF/QyugOwCfS2Gu jcJFn48T4uc+ooeSAaCkAhs= =pIel -----END PGP SIGNATURE-----

On Mon, 4 Aug 2003 10:01:50 +0000
"Thomas L. Bevan"
-----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

Hi, Thomas-- At 10:01 AM +0000 8/4/03, you wrote:
Is there any reason why show :: String -> String is not equivalent to 'id' ?
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 _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Actually, this definition of show :: String -> String is consistent with the definitions of show for other familiar types. That is, it produces the string by which its argument's value would be represented as a literal value in Haskell code. A String literal is enclosed in quotation marks, and characters such as new-lines, tabs, and quotation marks are represented by \-sequences. Ergo, the first and last characters of the value of (show (x::String)) are always quotation marks, and each newline, tab, or quotation mark in x will appear in (show x) as a two-character \-sequence. I'm not sure what you mean by "... requires String to be treated as a special case, rather than just a member of Show". What sort of special treatment did you have in mind? Regards, --Ham -- ------------------------------------------------------------------ Hamilton Richards, PhD Department of Computer Sciences Senior Lecturer The University of Texas at Austin 512-471-9525 1 University Station C0500 Taylor Hall 5.138 Austin, Texas 78712-1188 ham@cs.utexas.edu hrichrds@swbell.net ------------------------------------------------------------------
participants (3)
-
Derek Elkins
-
Hamilton Richards
-
Thomas L. Bevan