Add non-escaping show functions

Kai Ma justksqsf at gmail.com
Sun Dec 19 09:53:47 UTC 2021


Hi all!

A few months ago I proposed to change the escaping behavior of `show`. The general consensus is that it will introduce hard-to-find and unpredictable amount of breakage.

However, I still think there should be a standard (i.e. living in base) solution to that problem. Instead of changing existing instances, we can add new functions. Therefore, I propose:

1. Add `showNE` [1] to `Show`, with a default implementation `showNE = show`.
2. Add `printNE x = putStrLn (showNE x)`.
3. Change ghci’s default print function to `printNE`.
4. Document that `show` escapes strings so its output will support ASCII terminals, where `showNE` is limited to only terminals that support Unicode.

This proposal benefits ghci without breaking any existing code, and the older behavior can be restored by `:set -interactive-print print`.

Q&A:

- Why not just use existing packages, like pretty-simple, for this purpose?

  I believe ghci should support this behavior (non-escaping) out of box without installing any third-party packages.

- Why not just add `printNE` which undoes escaping?

  Definitely doable. However, it feels more like a hack than a solution.

According to the new CLC process, this proposal should be submitted to https://github.com/haskell/core-libraries-committee/issues. But I’d like to hear some early feedback, and I will implement this proposal.

[1] “NE” stands for non-escaping. This is only a temporary name in order to avoid bike-shedding.

Regards,
Kai


More information about the Libraries mailing list