On 10-Jun-1998, Karlsson Kent - keka <[EMAIL PROTECTED]> wrote:
| It's nice to have SOME way of handling exceptions, but...
|
| > The implementation does not keep sets of exceptional values,
| > of course. It simply propagates the first one it trips
| > over to the nearest enclosing handler.
|
| One argument that can be made in favour of a generalised more IEEE-like
| mechanism is that it is usually such a pain to handle an exception that
| propagates like this that one most often does not bother to handle it
| properly (i.e. try to continue with the task, which is usually the best
| thing to do; [...]). And in many cases, using some reasonable
| 'continuation value' (which have already been specified and widely
| implemented for f.p. arithmetic) and a set of notes on exceptions that
| have occurred, is sufficient and gives a nicer behaviour of the program.
|
| Say that the application is to produce a simple function curve, for a
| function given as argument, so only the type is known and no other
| properties. Say that it does this by computing a list of pairs later to
| be turned into a nice-looking graph. Say also that overflows occur, or
| out-of-domain-errors occur. Having these errors propagate up to an IO
| monad or similar for handling, then having to restart, in the handler,
| the graph calculation at the appropriate place is much more difficult to
| handle (and is likely not to be done, or to be done in a buggy way) than
| just plodding on as if (nearly) nothing out of the ordinary happened.
With the `NDSet' module I described in another post, this
is straightforward. Suppose your function which returns a list
of pairs is defined as
compute_graph :: SomeData x y -> [(x, y)]
Then you can easily catch exceptions in the computation of the y's.
You don't even need to modify the code for compute_graph!
checked_compute_graph :: SomeData x y -> [(x, MaybeException y)]
checked_compute_graph somedata = (xs, map ndset_catch ys) where
list = compute_graph somedata
xs = map fst list
ys = map snd list
Then the code which draws the graph just needs to do some pattern
matching on the `MaybeException y' at the appropriate place:
plot_point x (OK y) = ...
plot_point x (GotException exception) = ...
--
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.