
Hello! I'm sure this has been answered many times before, but I can't find an explanation for this behavior anywhere. The question I have is a general one regarding 'show'. Why does main = do putStrLn "ü" ➜ ~ runhaskell test.hs ü and: main = do putStrLn $ show "ü" ➜ ~ runhaskell test.hs "\252" Thank you all for an enlightening answer already! Best, k

"Show" is for debug output. It's not a generic "to_string". See this thread
[1] from last week for more info.
- Clark
[1] https://groups.google.com/forum/#!topic/haskell-cafe/32EeI96b1VQ
On Wed, Mar 5, 2014 at 4:43 PM,
Hello!
I'm sure this has been answered many times before, but I can't find an explanation for this behavior anywhere. The question I have is a general one regarding 'show'. Why does
main = do putStrLn "ü"
➜ ~ runhaskell test.hs ü
and:
main = do putStrLn $ show "ü"
➜ ~ runhaskell test.hs "\252"
Thank you all for an enlightening answer already!
Best,
k _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Clark. Key ID : 0x78099922 Fingerprint: B292 493C 51AE F3AB D016 DD04 E5E3 C36F 5534 F907

Okay, it makes somewhat more sense now after reading that thread. But technically, why does show "ü" not handle Unicode? Isn't the internal representation of [Char] actually still Unicode, as per [1]http://hackage.haskell.org/package/base-4.6.0.1/docs/Data-Char.html Thanks! k On Wed, Mar 5, 2014, at 01:46 PM, Clark Gaebel wrote: "Show" is for debug output. It's not a generic "to_string". See this thread [1] from last week for more info. - Clark [1] [2]https://groups.google.com/forum/#!topic/haskell-cafe/32EeI96b1VQ On Wed, Mar 5, 2014 at 4:43 PM, <[3]k@ioctl.it> wrote: Hello! I'm sure this has been answered many times before, but I can't find an explanation for this behavior anywhere. The question I have is a general one regarding 'show'. Why does main = do putStrLn "ü" ➜ ~ runhaskell test.hs ü and: main = do putStrLn $ show "ü" ➜ ~ runhaskell test.hs "\252" Thank you all for an enlightening answer already! Best, k _______________________________________________ Haskell-Cafe mailing list [4]Haskell-Cafe@haskell.org [5]http://www.haskell.org/mailman/listinfo/haskell-cafe -- Clark. Key ID : 0x78099922 Fingerprint: B292 493C 51AE F3AB D016 DD04 E5E3 C36F 5534 F907 References 1. http://hackage.haskell.org/package/base-4.6.0.1/docs/Data-Char.html 2. https://groups.google.com/forum/#!topic/haskell-cafe/32EeI96b1VQ 3. mailto:k@ioctl.it 4. mailto:Haskell-Cafe@haskell.org 5. http://www.haskell.org/mailman/listinfo/haskell-cafe

On Wed, Mar 5, 2014 at 5:20 PM,
Okay, it makes somewhat more sense now after reading that thread. But technically, why does
show "ü"
not handle Unicode? Isn't the internal representation of [Char] actually still Unicode, as per
Historical reasons, I imagine; Unicode I/O support is still relatively recent in GHC, and I doubt anyone went back and revisited the Show instance for Char. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

Show is supposed to convert its argument into a haskell expression which,
when evaluated, returns the same value that was initially passed to show.
So by this definition, "\252" is just as correct as "ü".
There are some Show instances out in the world that do not follow this
rule, but they are bad. I'm looking at you, Network.URI!
On Wed, Mar 5, 2014 at 2:20 PM,
Okay, it makes somewhat more sense now after reading that thread. But technically, why does
show "ü"
not handle Unicode? Isn't the internal representation of [Char] actually still Unicode, as per
http://hackage.haskell.org/package/base-4.6.0.1/docs/Data-Char.html
Thanks!
k
On Wed, Mar 5, 2014, at 01:46 PM, Clark Gaebel wrote:
"Show" is for debug output. It's not a generic "to_string". See this thread [1] from last week for more info.
- Clark
[1] https://groups.google.com/forum/#!topic/haskell-cafe/32EeI96b1VQ
On Wed, Mar 5, 2014 at 4:43 PM,
wrote: Hello!
I'm sure this has been answered many times before, but I can't find an explanation for this behavior anywhere. The question I have is a general one regarding 'show'. Why does
main = do putStrLn "ü"
➜ ~ runhaskell test.hs ü
and:
main = do putStrLn $ show "ü"
➜ ~ runhaskell test.hs "\252"
Thank you all for an enlightening answer already!
Best,
k _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Clark.
Key ID : 0x78099922 Fingerprint: B292 493C 51AE F3AB D016 DD04 E5E3 C36F 5534 F907
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 06/03/14 03:53, David Fox wrote:
Show is supposed to convert its argument into a haskell expression which, when evaluated, returns the same value that was initially passed to show. So by this definition, "\252" is just as correct as "ü".
There are some Show instances out in the world that do not follow this rule, but they are bad. I'm looking at you, Network.URI!
What about instances where we can't have a reasonable Show that fulfills your requirement? Say, any structure which encapsulates a function. While I agree that ideally Show (or some other typeclass) would be used so that ‘read’ also works, it's not always possible. If people are expected to follow the implicit Show rules then perhaps base functions such as ‘print :: Show a => a -> IO ()’ shouldn't be using Show to begin with! It's inconvenient to not make Show instances/make the instances be readable if all the functions that actually let us have a look at the structures use ‘Show’. ‘print’ is great and no one is going to abandon in because one of the 30 fields in their structure happens to be a function. -- Mateusz K.

On 06/03/14 03:53, David Fox wrote: What about instances where we can't have a reasonable Show that fulfills your requirement? Say, any structure which encapsulates a function.
Then you write a custom show function that does the best it can. For what it's worth, Smalltalk has historically had thing printOn: stream write thing on stream for people to read thing storeOn: stream write thing on stream so that #readFrom: can read it back and functions (which Smalltalk calls 'blocks') basically defeat both of them.

On 03/06/2014 05:21 AM, Mateusz Kowalczyk wrote:
‘print’ is great and no one is going to abandon in because one of the 30 fields in their structure happens to be a function.
I write Pretty instances, it's much easier thanks to all the combinators, it is better suited for human consumption (some libraries have colours), and it's not confusing. Once you have good Pretty instances, you also have great logging and error messages, as opposed to some string that only makes sense to a developer. The only drawback are the orphan instances, if you really need to defined them for a type that's not yours (but you usually don't).

On 06/03/14 07:17, Simon Marechal wrote:
On 03/06/2014 05:21 AM, Mateusz Kowalczyk wrote:
‘print’ is great and no one is going to abandon in because one of the 30 fields in their structure happens to be a function.
I write Pretty instances, it's much easier thanks to all the combinators, it is better suited for human consumption (some libraries have colours), and it's not confusing. Once you have good Pretty instances, you also have great logging and error messages, as opposed to some string that only makes sense to a developer.
The only drawback are the orphan instances, if you really need to defined them for a type that's not yours (but you usually don't). _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Which package are you using for this? I'd like to add that in some cases (GHC, Haddock, any base libraries) it is not possible to add such a dependency which means that a lot of the time you're stuck with the stock stuff (Show, IsString). -- Mateusz K.

On 03/06/2014 08:20 AM, Mateusz Kowalczyk wrote:
Which package are you using for this?
I use ansi-wl-pprint because it has colors. Unfortunately, I went overboard with it :) http://lpuppet.banquise.net/images/collision-error.png

Which package are you using for this?
I'd like to add that in some cases (GHC, Haddock, any base libraries) it is not possible to add such a dependency which means that a lot of the time you're stuck with the stock stuff (Show, IsString).
I'd be interested to know too! Anyways, the purpose (and limitations) of Show in this case seem definitely clearer now, so thanks to you all for responding. From the perspective of a beginner, I have to admit that its definitely confusing though. Cheers, k -- Karsten Gebbert http://ioctl.it mob: 0049 (0) 176 61995110
participants (8)
-
Brandon Allbery
-
Clark Gaebel
-
David Fox
-
k@ioctl.it
-
Karsten Gebbert
-
Mateusz Kowalczyk
-
ok@cs.otago.ac.nz
-
Simon Marechal