Discussion: adding displayException to Exception class

Christopher Done chrisdone at gmail.com
Thu Oct 30 10:20:00 UTC 2014


On 30 October 2014 11:00, Tobias Florek haskell at ibotty.net
<http://mailto:haskell@ibotty.net> wrote:
Quoting Christopher Done (2014-10-29 23:07:54)

Well, I think fromList [(1, ‘a’)] is kind of unhelpful:

   1. It almost never is a straight copy/paste, you will have to go and add
   M. to
   the fromList.

 Chris Done is hinting at a shortcoming to the usage of Show in the sense
of Jeremy Shaw’s ShowExpr: It does not support qualified imports at all.

It might be nice to append a My.Module to each function in show‘s
output whenever a module is meant to be imported qualified. There might
be some heuristics on when that’s the case (hiding parts of Prelude),
but that’s certainly something only the compiler (or TH) can do.

Technically Data.Typeable has this information:

> tyConModule (typeRepTyCon (typeOf (S.fromList [()])))"Data.Set.Base"
> tyConName (typeRepTyCon (typeOf (S.fromList [()])))"Set"
> tyConPackage (typeRepTyCon (typeOf (S.fromList [()])))"containers-0.5.5.1"

Data.Generics.Text
<http://hackage.haskell.org/package/syb-0.3.6/docs/Data-Generics-Text.html>
can give a more structured output (though it doesn’t), but then there lies
the issue:

> gshow TruncatedArchive

<interactive>:25:1:
    No instance for (Data FormatError) arising from a use of ‘gshow’
    In the expression: gshow TruncatedArchive
    In an equation for ‘it’: it = gshow TruncatedArchive

Hardly any data types are actually instances of Data. And the ones that are
can often be bogus, even “standard” ones like Data.Vector and Data.Text:

> gshow (V.fromList [1])
"(*** Exception: toConstr

> gshow (T.pack "x")
"(*** Exception: Data.Text.Text.toConstr

So while Data.Data could be a perfect solution for printing, at the moment
it can’t be relied upon to exist.
​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20141030/45cc1e41/attachment-0001.html>


More information about the Libraries mailing list