<br><br><div class="gmail_quote">On Mon Nov 10 2014 at 8:28:18 PM Michael Snoyman <<a href="mailto:michael@snoyman.com">michael@snoyman.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote">On Mon Nov 10 2014 at 7:17:07 PM Simon Hengel <<a href="mailto:sol@typeful.net" target="_blank">sol@typeful.net</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> > So I would love to have tho following type class:<br>
> ><br>
> >     class Display a where<br>
> >       display :: a -> String<br>
> >       default display :: Show a => a -> String<br>
> >       display = show<br>
> ><br>
> > Note that for many Prelude types `show == display`, with the notable<br>
> > exception of String, where `display = id`.  One use case where this<br>
> > matters is string interpolation [1][2][3].<br>
><br>
> I would also like a class like that to exist.<br>
><br>
> But I think it should be based on Text and Text builder rather than<br>
> String (and hence be outside of base).<br>
<br>
I created an initial draft:<br>
<br>
    <a href="https://github.com/sol/display/blob/master/src/Data/Display.hs" target="_blank">https://github.com/sol/<u></u>display<u></u>/blob/master/src/Data/<u></u>Display.<u></u>hs</a><br>
<br></blockquote><div><br></div></div><div class="gmail_quote"><div>Is this intended to be a standalone library, or part of text (or some other package?).</div></div><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I named the builder version `displayBuilder` as I could not come up with<br>
any better name (suggestions much appreciated!).<br>
<br>
In addition, I think the `display` method has to be outside of the<br>
class.  Otherwise, if somebody defines `display` he end up with the<br>
default implementation of `displayBuilder` (which is based on show and<br>
may not be what is intended).  Any input on that?<br>
<br></blockquote><div><br></div></div><div class="gmail_quote"><div>I don't think this is a good enough reason to avoid a possible optimization. I'd recommend documenting this aspect of the typeclass thoroughly, and then let people shoot themselves in the foot if desired.</div></div><div class="gmail_quote"><div><br></div><div>Michael</div></div><div class="gmail_quote"><div><br></div><div>PS: I just saw Greg's email, I'd like to +1 his questions, clarification is good.</div></div></blockquote><div><br></div><div>One other question/comment: I'm not convinced that the `String` instance is a good thing. It will conflict with any other list instance, unless you turn on OverlappingInstances (which I hope you don't). You could use the `showList` hack, but we should really clarify first what the intended list instance is.</div><div><br></div><div>Michael </div></div>