[RFC] Support Unicode characters in instance Show String

Viktor Dukhovni ietf-dane at dukhovni.org
Thu Jul 8 20:00:37 UTC 2021


On Thu, Jul 08, 2021 at 10:48:28PM +0300, Oleg Grenrus wrote:

> GHC Manual: Using a custom interactive printing function [1]
> 
>     Prelude Data.Char> "foo"
>     "foo"
>     Prelude Data.Char> let myprint=putStrLn . map toUpper . show
>     Prelude Data.Char> :set -interactive-print myprint
>     Prelude Data.Char> "foo"
>     "FOO"
> 
> I remember some people using e.g. pretty-show or pretty-simple packages
> with great success.
> 
> No need to change anything in base, just make users aware of a configuration
> possibility.

This is NOT viable, not all escapes are valid to unescape after the fact
in a print function.  Which pieces of the `show` output are escaped
unicode characters, and which are not depends on the original data type
that got serialised to a given `String`.

For example, in a `ByteString` the octet '\xFC' should display
as '\252', while in a `String` or `Text` U+00FC should display
as 'ü'.   Thus, there is no correct unescape function for the
string "M\\252ller", it could be "Müller", or not...

-- 
    Viktor.


More information about the Libraries mailing list