Discussion: adding displayException to Exception class

Michael Snoyman michael at snoyman.com
Wed Oct 29 11:46:32 UTC 2014


On Wed, Oct 29, 2014 at 1:43 PM, Dominique Devriese <
dominique.devriese at cs.kuleuven.be> wrote:

> 2014-10-29 12:25 GMT+01:00 Michael Snoyman <michael at snoyman.com>:
> > [possible use cases for Show]
> > 1. Express a valid Haskell expression for copy/paste reasons.
> > 2. Express a valid Haskell expression to make it easy to determine the
> type
> > of the exception thrown (even though that's not always enough
> information).
> > 3. Express something that can be consumed by Read for easy serialization.
> > 4. Print something which is meaningful to a Haskell developer.
> > 5. Print something which would be meaningful to an end user.
>
> If we enter this discussion, I think we should keep in mind how some
> of these uses are encouraged by the infrastructure.  Specifically:
> * the fact that GHCi uses Show for printing result values, counts (at
> least for me) as an implicit vote for use case (4)
> * the fact that deriving Show is directly supported by the compiler
> (contrary to Binary, for example) making it easier to use Show than
> more appropriate alternatives.  If we think Show is the wrong solution
> for serialisation, then maybe the compiler should provide equivalent
> support for a more adequate solution, for example?
>
> Regards,
> Dominique
>

Those are good points. For your first one: that's why my quasi-proposal
stated that GHC's default exception handler should switch over to using the
new pretty-printed exception method (since I'd like (5) to be the target in
that case). Regarding your second point: Generic-based instances go a long
way towards solving that problem, and- unless I'm mistaken- starting with
GHC 7.10 it will be possible to do something like:

data Foo = ...
    deriving (Generic, Binary, ToJSON, FromJSON)

Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20141029/de4740b4/attachment.html>


More information about the Libraries mailing list