snoyberg / classy-prelude

A typeclass-based Prelude.
108 stars 15 forks source link

Problem with return type polymorphism #59

Closed mihao closed 11 years ago

mihao commented 11 years ago

With standard Prelude I can write Text.Blaze.Html5.toHtml (show 1). With classy-prelude I can't, because the value of show can be a String, Text, LText, etc., and toHtml can accept any of these types. Wouldn't it be better if show simply returned a String? If we wanted something else, we'd have to do the conversion explicitly. Right now we have to always specify the type in such situations, so we get more boilerplate code, instead of less.

show is just an example, this problem may affect other functions as well.

snoyberg commented 11 years ago

I've also felt uncomfortable about the custom show, since it makes it difficult to write a manual Show typeclass instance. I'm OK with getting rid of this special handling.

On a related note, I've also been thinking about adding some kind of typeclass for displayable values, which (unlike Show) would be intended for user display, and would not have any implied association with the Read class. Perhaps doing these two things at the same time would make sense.

Pinging @maxcan and @gregwebs for input.

gregwebs commented 11 years ago

I would probably be happy if there were a separate show for both Strict Text and String. tshow perhaps?

I started using wl-pprint-extras and wl-pprint-terminfo and released hspec integration: http://hackage.haskell.org/package/hspec-expectations-pretty

snoyberg commented 11 years ago

OK, I've pushed a commit, and exposed tshow.

wl-pprint* seems a bit heavy weight for a replacement for show in common cases. I would have thought building on top of text Builders would be a closer fit. But I'll admit that I haven't thought about the problem very much yet.

gregwebs commented 11 years ago

wl-pprint is a bit heavy weight depending on what you had in mind. One important thing that it does though is let you create default instances from the Show instance, which reduces the effort to get some instances going.