Proposal: Extensible exceptions

Isaac Dupree isaacdupree at
Mon Jul 7 14:53:52 EDT 2008

Isaac Dupree wrote:
> I have type issues.

Oh, I forgot to mention: this type is probably a mistake:
mapException :: (Exception e) => (e -> e) -> a -> a
That only allows mapping from any class of exceptions to the same class!

Perhaps this would work better:
mapException :: (SomeException -> SomeException) -> a -> a
although I'm not sure how happy I am with the usage of that type (even 
though it's a "correct" one).  I've never used mapException myself 
though, so I couldn't say.
mapException :: (Exception e) => (e -> SomeException) -> a -> a
mapException :: (Exception e1, Exception e2) => (e1 -> e2) -> a -> a
, and perhaps
mapAnyException :: (SomeException -> SomeException) -> a -> a

Even, maybe a `mapExceptions` similar to `catches`, although I cringe at 
what it would do with Handler.  I tried replacing
catches :: IO a -> [Handler a] -> IO a
data Handler a = forall e . Exception e => Handler (e -> IO a)
catches :: IO a -> [Handler (IO a)] -> IO a
data Handler a = forall e . Exception e => Handler (e -> a)
, but it still doesn't quite seem to work happily? I guess this is 
mapExceptions :: [Handler SomeException] -> a -> a
data Handler2 = forall e1 e2. (Exception e1, Exception e2)
     => Handler2 (e1 -> e2)
might be ideal, and
mapExceptions :: [Handler Zero] -> a -> a
where "Zero" is the type that only contains _|_, obviously work just as 

I'm not sure how hard it is for user-level code to deal with 
SomeException directly.  If it's not that hard to do, probably
mapException :: (SomeException -> SomeException) -> a -> a
is the most expedient choice for us?


More information about the Libraries mailing list