In the backchannel, Alastair Reid and Adrian Hey, have convinced me
that the return values of functions and cannot be represented using
algebraic types.

In a lazy language, a function may have an error/exception either because
it actually uses the value of one of its arguments (whose evaluation
causes an exception) or because it itself does something bad e.g. pattern
match failure.

Since a lazy language does not define the order in which functions get
executed or in which arguments are evaluated, there is no 1-1 mapping from
arguments to an exception value.  However, referential transparnecy does mean
that any exception outside the IO Monad represents a violation of a
precondition to the top level function (I am ignoring memory errors for
the moment).  So that the IOMonad caller should be able to handle the
exception and adjust in some sane manner.
In production programs (servers), it is very important to avoid program
suicide and do something sane with errors.

Doing something sane means that error messages have to be processable.
Therefore functions outside the I/O monad should still be
allowed to throw typed exceptions.  It is just that those  
exceptions should not be converted into a return value by higher level
handlers.  Instead, to ensure that functions throw exceptions that are
understandable by their caller, handlers should 
transform lower level exceptions into exceptions that are meaningful to
the caller.

I am not sure of syntax, but I am describing something like:

> type Handler a b = Exception a -> Exception b

and a function that may have exceptions should define the type of its
exceptions:

> data MyException a b c = SomeExpetion a | OtherException b 
> fun:: a->b->c :: MYException a b c
> fun x y = if x/= then numerator/denominator else throw SomeException x
>  where numerator   = x
>        denominator = y
>  catch DivisionByZero=throw OtherException y

Any exception type not explicitly caught is passed up raw.

I don't know how feasable this is, but providing minimal ability to catch
error messages would be better.  (You could always parse the error
messages).

-Alex-


 
___________________________________________________________________
S. Alexander Jacobson                   i2x Media  
1-212-697-0184 voice                    1-212-697-1427 fax



Reply via email to