Data.Display - Textual representation of Haskell values (was Re: PROPOSAL: Add displayException to Exception typeclass)

Simon Hengel sol at typeful.net
Mon Nov 10 17:16:51 UTC 2014


> > So I would love to have tho following type class:
> >
> >     class Display a where
> >       display :: a -> String
> >       default display :: Show a => a -> String
> >       display = show
> >
> > Note that for many Prelude types `show == display`, with the notable
> > exception of String, where `display = id`.  One use case where this
> > matters is string interpolation [1][2][3].
>
> I would also like a class like that to exist.
>
> But I think it should be based on Text and Text builder rather than
> String (and hence be outside of base).

I created an initial draft:

    https://github.com/sol/display/blob/master/src/Data/Display.hs

I named the builder version `displayBuilder` as I could not come up with
any better name (suggestions much appreciated!).

In addition, I think the `display` method has to be outside of the
class.  Otherwise, if somebody defines `display` he end up with the
default implementation of `displayBuilder` (which is based on show and
may not be what is intended).  Any input on that?

Pleas bikeshed hard!

Cheers,
Simon


More information about the Libraries mailing list