On Mon, 8 Jun 1998, S. Alexander Jacobson wrote:

> 1. it is not logically consistent to treat exceptions as return values

A function cannot do anything but return a value, can it? 

> For example, suppose that we define a new function:
> 
> > foo' a b = a + b -- foo' is strict in its arguments
> 
> Our intuition is that foo' is commutative.  foo' a b = foo' b a.
> But that turns out not to be true when you have exceptions.

That's the problem with intuitions: they can be wrong...  
Anyhow, if one is to have exceptions procteting +, I don't think that
commutativity of foo' is reasonable: to handle exceptions, you have to do
checks, and that you can only do in one order or another. 

> Take x and y from before,
> 
> > z = foo' x' y'
> 
> What is the value of z? Haskell does not promise to evaluate arguments in
> any particular order so, depending on implementation, z may be either
> Exception DivideByZero or Exception NotFactorialDomain -1.  

Actually, using a monad to manage exceptions you can (maybe, have to) 
choose a definite order of evaluation of non-exceptionality-conditions. 

> Truly exceptional conditions are those that truly are outside of the
> domain of the function being evaluated. e.g. factorial -1
> The VALUE of (factorial -1) is not an exception.  Neither is the value of
> (factorial (1 `div` 0)).
> When a function is passed bad arguments, it is not meaningful (from a
> functional perspective) to have it return a value.

In a typed language, a function *cannot* be applied to something outside
its domain. That's the whole point!

> The value of a function over arguments outside its domain is undefined.
> When such an event occurs, the logically consistent behavior is to exit
> function evaluation and tell the caller what was wrong with the
> arguments passed (to the extent it is possible to do).

One can rightfully argue that, if one is willing to consider bottom (which
is a value we cannot test for!) a return value, which we are, considering
an exception a return value is *very* consistent. 
 
-- m

-----------------------------------------------------------------------
Mariano Suarez Alvarez                              The introduction of
Departamento de Matematica                       numbers as coordinates
Universidad Nacional de Rosario             [...] is an act of violence
Pellegrini 250                                                  A. Weyl
2000 Rosario - Argentina                                        
e-mail: [EMAIL PROTECTED]
-----------------------------------------------------------------------


Reply via email to