On 10-Jun-1998, Hans Aberg <[EMAIL PROTECTED]> wrote:
> At 01:09 +1000 98/06/11, Fergus Henderson wrote:
> >There's little point trying to implement C++-like so-called "zero-overhead"
> >exceptions in any language with garbage collection.  It would
> >probably result in a performance loss.
> 
>   This is good indeed.
> 
>   But I think the C++ exceptions have another advantage, namely that it
> stops further computations and skips directly forward to the first point
> where the exception is caught. Java, which has garbage collection, probably
> does the same as in C++, but when using the monadic approach in Haskell it
> does not work so: The code excepted propagates through a series of identity
> mappings in the exception monad, which is slow.

Well, there's basically three ways that I know of to implement exceptions,
other than the C++ "zero-overhead" style:

        (a) have every function return an indicator saying whether it
          succeeded or threw an exception, and after each function
          call this indicator and if it is an exception, rethrow it

        (b) use a special stack frame for exception handlers;
          ordinary returns incur no overhead, but throws
          need to scan the stack looking for handlers

        (c) use a seperate stack for exception handlers;
          ordinary returns incur no overhead, and
          when an exception is thrown it need only
          look at the topmost entry on the exception handler stack.
          But having an extra stack complicates things,
          and may make threads more expensive, etc.

Clearly (a) is not very good.  You seem to be arguing for (c),
but I think that in practice the improvement from (b) to (c)
is not likely to be important for the vast majority of programs.
I suspect you would be happy with (b).

>   So the real problem is if one can implement an exception monad in Haskell
> which does not propagate through the code (i.e. skips forward directly to
> the point where the exception is caught).

Yes, this ought to be possible -- indeed SLPJ alluded to doing that kind of
thing when he talked about improved I/O performance.  I think he was
talking about (b) rather than (c), though.

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]        |     -- the last words of T. S. Garp.


Reply via email to