
On Tue, 28 Aug 2001, Simon Marlow wrote: (snip)
In GHC, you can do this:
import Exception
do result <- catch (evaluate (read "foo" :: Int)) (\error -> ... ) (snip)
I do like that. Is it likely to become standard someday, do you think? Errors like this should certainly be catchable in such a way; I was sad when I was first looking into this and found that 'catch' seemed to be inextricably linked to IO.
Well, we'd like it to become standard :-) The exception stuff is really very easy to implement - you just use the standard stack-unwinding implementation of throw, and catch has to push a special stack frame. GHC's asynchronous exceptions are slightly harder, but I don't think it was more than a day or two's work. As a bonus you get to use a more efficient implementation of the IO monad, because it doesn't have to deal explicitly with exceptions. And then IO becomes a straightforward instance of ST. I guess I should also document the Exception extension in a self contained way, similar to the way the FFI extension is documented. Cheers, Simon

Simon Marlow writes (of Exception handling a la GHC/Hugs):
Well, we'd like it to become standard :-) The exception stuff is really very easy to implement - you just use the standard stack-unwinding implementation of throw, and catch has to push a special stack frame. GHC's asynchronous exceptions are slightly harder, but I don't think it was more than a day or two's work.
I can see synchronous exceptions being standardised in the near term. The Exception library probably needs a little more time to stabilise since it just recently got a redesign. OTOH, asynchronous exceptions seem further off. 1) I doubt may people have experience using them - so the current design probably hasn't been tested hard enough. 2) We need to standardise threads first. 3) I have no idea how I would add asynchronous exceptions to Hugs. Some of the basic problems are: 1) Hugs doesn't maintain anything like a Thread Control Block or anything else that would provide a natural definition of threadid. 2) Hugs doesn't maintain a separate stack per thread so the standard stack trimming implementation doesn't really work. 3) Hugs doesn't provide preemptive scheduling of threads so asynchronous exceptions are less useful. [I suspect that NHC is in a similar position] All this could be worked on but it's certainly not a day or two's work. -- Alastair Reid reid@cs.utah.edu http://www.cs.utah.edu/~reid/
participants (2)
-
Alastair David Reid
-
Simon Marlow