[core libraries] Future of "Text.Show.Functions" module

Michael Snoyman michael at snoyman.com
Sun Oct 19 12:59:45 UTC 2014


On Sun, Oct 19, 2014 at 1:20 PM, Herbert Valerio Riedel <hvr at gnu.org> wrote:

> Hello *,
>
> I noticed the following module (trimmed for brevitiy) hiding in `base`:
>
>
>   -- This module deliberately declares orphan instances:
>   {-# OPTIONS_GHC -fno-warn-orphans #-}
>
>   -- | Optional instance of 'Text.Show.Show' for functions:
>   --
>   -- > instance Show (a -> b) where
>   -- >    showsPrec _ _ = showString \"\<function\>\"
>   --
>
> -----------------------------------------------------------------------------
>
>   module Text.Show.Functions () where
>
>   instance Show (a -> b) where
>           showsPrec _ _ = showString "<function>"
>
>
> However, I consider this a questionable module to be in `base` due to
> its deliberate use of orphan instances.  Should this module be
> deprecated, removed, alternatively, should the `Show` instance be made a
> non-orphan (e.g. by importing it by the `Prelude` module), or shall this
> curiousity be just left untouched in `base` in its current form?
>
> Cheers,
>   hvr
>
> --
> You received this message because you are subscribed to the Google Groups
> "haskell-core-libraries" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to haskell-core-libraries+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

I think this really brings up the question of what `Show` should be used
for. If the goal is to be simple serialization with `Read` as the
inverse[1], then this is clearly a nonsense instance and shouldn't be
included. If, on the other hand, we consider `Show` to be simple debug
output, this makes perfect sense. Similarly, rendering `IO a` as "<IO
action>" or something like that makes sense too.

An example where this came up recently was adding a Show instance to the
Request type in WAI[2]. The goal there is explicitly debugging, and
displaying some uninteresting string for any IO actions is very useful.
Having such an instance built into base would have been convenient for
auto-deriving of this Show instance.

Overall, the problem is that we've overloaded Show in (at least) three
different ways:

* Textual serialization
* Debugging
* User-friendly display of data

I think I give a +0.5 to re-exporting this instance from Prelude/making it
non-orphan, since:

1. I agree that orphans in base are a bad idea.
2. Removing the instance will possibly cause breakage for someone.
3. I *do* personally lean towards using Show instances for debugging
purposes, and in that context, the Show instance is a good one.

Michael

[1] I believe the correct term is actually a retraction.
[2] https://github.com/yesodweb/wai/issues/290
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20141019/915d9f7c/attachment.html>


More information about the Libraries mailing list