Discussion: adding displayException to Exception class

Michael Snoyman michael at snoyman.com
Wed Oct 29 10:58:56 UTC 2014


On Wed, Oct 29, 2014 at 10:39 AM, Herbert Valerio Riedel <hvr at gnu.org>
wrote:

> Hi Michael,
>
> On 2014-10-29 at 00:43:55 +0100, Michael Snoyman wrote:
> > I don't want to make a format proposal yet, just open up discussion on an
> > issue, and see how others feel about it.
> >
> > As I recently commented on this list[1], the Show typeclass is overloaded
> > with multiple meanings (serialization, debug info, and user-friendly data
> > display). The general consensus seems to be that the official semantics
> for
> > Show should be for serialization (as paired up with Read).
>
> [...]
>
> > I have a possible solution that I'd like to propose as a strawman: add a
> > new method to the Exception typeclass:
> >
> >     displayException :: e -> String
> >     displayException = show
>
> As we're having the general problem of 'Show' being abused for
> pretty-printing, why not rather standardise on a pretty-show/printing
> typeclass that would not be limited to Exceptions? What am I missing?
>
>
The downside to that is that it introduces a breaking change, whereas this
proposal does not. If we *do* want to standardize on a pretty-printing
typeclass, I think the right way forward (though somewhat painful) is:

Release X: Introduce the pretty-printing typeclass, add displayException
with default implementation of Show, do not otherwise change Exception.
Release X+1: Add new typeclass as a superclass of Exception.
Release X+2: Switch default implementation of displayException to the
pretty-show.
Release X+3: Remove Show as a superclass.

Maybe some of those steps can be combined, I'm not certain.

Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20141029/84917a78/attachment.html>


More information about the Libraries mailing list