Proposal: Add Eq instance for Control.Exception.ErrorCall

Michael Snoyman michael at snoyman.com
Tue Nov 27 12:44:02 CET 2012


On Tue, Nov 27, 2012 at 1:12 PM, Henning Thielemann <
lemming at henning-thielemann.de> wrote:

>
> On Tue, 27 Nov 2012, Simon Hengel wrote:
>
>  I propose to add an Eq instance for ErrorCall.  The main motivation is
>> to make it more convenient to construct predicates that select specific
>> exceptions.
>>
>> My current use case is testing for expected exceptions.  In Hspec[1] we
>> use predicates for that, e.g.:
>>
>>  evaluate (head []) `shouldThrow` (== ErrorCall "Prelude.head: empty
>> list")
>>
>
>
> If this is an actual use case, then there is something very wrong.
> Handling non-empty lists can be done cleanly using various non-empty list
> types. Or you avoid 'head' by using 'case' or 'viewL'. If instead you plan
> to catch something then you should use Either, ExceptionalT, ErrorT or IO
> exceptions. I am afraid that an Eq instance for ErrorCall promotes the
> abuse of 'error'.
>
>
+1 on the proposal. Even if I'm opposed to partial functions, I'm in favor
of making it easier to test them reliably.

Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20121127/06be7e0d/attachment.htm>


More information about the Libraries mailing list