mapException

Lauri Alanko la@iki.fi
Sat, 16 Nov 2002 11:18:12 +0200


On Mon, Nov 04, 2002 at 01:00:39PM -0000, Simon Marlow wrote:
> and the awkward squad paper will have to be updated to comply (although
> we just noticed it is already wrong about the behaviour of
> Prelude.catch).

This reminds me: in the paper "A semantics for imprecise exceptions" a
primitive "mapException" is introduced:

mapException :: (Exception -> Exception) -> a -> a

However, I don't think GHC's exception library has ever had this. Is
this just a lapse, or is there some fundamental problem with a non-IO
mapException? The paper says that "its usefulness and desirability might
be debatable", but to me this seems very useful. Eg. in Java this is a
common idiom:

try {
	aux.library.Thing.doSomething();
} catch (aux.library.ThingException e) {
	throw new MyException(e.getProblem());
}

That is, one module uses another module internally to do a task, but of
course wishes to hide any implementation details from the caller.
Therefore we don't want to show the auxiliary library's exception
interface to the caller, but convert exceptions to match the publicly
defined exception interface.

It'd be very inconvenient if doing this in Haskell would require making
a formerly pure function use the IO monad.


Lauri Alanko
la@iki.fi