Could someone explain to me why the show function on string is not id function? For example
show (show 42) will return "\"42\"" what is weird and for me not intitutive.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
showisn’t very useful if it just converts something into an arbitrary string (liketoStringin Java). It is much more useful if the result is both easy to read and machine-readable, so a common use ofshowis to produce a serialized representation of the value that you areshowing, so that you can read it in again usingread, and also, for most implementations ofshow, so that you can type the string that isshown at a Haskell REPL likeghciand get the deserialized value back.So, if you have a string like
"42", andshowit, you want to get the string"\"42\"", because when you type42inghci(and equivalently using thereadfunction), you get a number, while when you type"42"inghci, you get the string that you want.