On 15-Jun-1998, Fergus Henderson <[EMAIL PROTECTED]> wrote:
> On 12-Jun-1998, Scott Turner <[EMAIL PROTECTED]> wrote:
> > At 14:40 1998-06-10 +0100, you wrote:
> > 
> > >Here's a reasonable design for exceptions in Haskell:
> > 
> > >* handle :: (String -> IO a) -> IO a -> IO a
> > 
> > You probably realized more quickly than I how this
> > can leak exceptions.
> ...
> > Is this considered a drawback?
> 
> This kind of exception handling can "leak" exceptions, but not in the
> way you described.
...
> > What I mean is
> > 
> > main = do quotient <- handle (const (return 0)) (return (0 / 0)
> >                          -- Looks plausible
> >                          -- but the exception isn't raised yet.
> >           print quotient -- Here the expression 0/0 is evaluated
> >                          -- and the exception is raised with no handler.
> 
> This is not correct.  This example would print out `0' rather than raising
> an uncaught division by zero exception.

I'm afraid I must retract those statements.  Scott Turner was quite correct,
and I was mistaken.  My apologies!

As Scott pointed out to me in personal email, SLPJ's definition of `handle'

>  | * handle :: (String -> IO a) -> IO a -> IO a
>  |   (handle h a) tries to perform the action a.
>  |   If doing so delivers a set of exceptional values then
>  |   apply the exception handler h to the string that names
>  |   one of them.  It is not defined which of the exceptional
>  |   values is picked.

means that it only catches exceptional values in the I/O action,
not exceptional values in the return value.

Regarding Scott's question

> Is this considered a drawback?

my answer is still much the same -- yes, it's a drawback,
but I'd place the blame more on laziness than exception handling.
I consider it only a minor drawback, since the "leakage" can be
avoided if you use a version of `handle' which is strict in the return
value, e.g.

        strict_handle handler action = handle handler strict_action where
                strict_action = do value <- action
                                   seq value return value
                                   -- or with `hyper_seq' instead of `seq'

-- 
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