Proposal: Add Eq instance for Control.Exception.ErrorCall
Henning Thielemann
lemming at henning-thielemann.de
Tue Nov 27 12:12:20 CET 2012
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'.
More information about the Libraries
mailing list