> > x= 1/0 - NaN

(I guess the - is supposed to be a --)

Actually, IEC 559 (a.k.a. IEEE 754, commonly referred to as 'IEEE
floating point') specifies that 1 floating point divided by (positive) 0
shall have the 'continuation value' of *positive infinity*, and (if
trapping is off) one shall record that a divide-by-zero has occurred.
The recording shall be such that it can be read and reset at a later
time (i.e. it shall not be reset automatically by the next f.p.
operation).  The default is to continue (arithmetic) calculations, even
if an exception occurs, though one can in principle request trapping.
Trapping, which in the IEEE sense can return back to the original
calculation, is rarely accessible from programming languages, except
assembler, as of yet.

Admittedly IEC 559 does not pay any attention to lazy purely functional
programming languages...


> fun:: Either a MyException -> Either b MyException -> Either c
MyException
...
>propagate2 :: a -> b -> c -> (Either a d -> Either b d -> Either c d)

Here it is suggested that one EITHER gets a 'proper value', OR an
'exception'.  But *closer* to the IEEE model of exceptions (most of the
examples, at least, emanate from arithmetic), if one ignores trapping,
is to give as return value BOTH a 'proper' value AND an exception
collection (usually empty, or contain just the value 'inexact'). Like
e.g. (I'm *not* suggesting anything for any programming language here):

add :: (Float, Exceptions) -> (Float, Exceptions) -> (Float, Exceptions)

Even if the 'Exceptions' values for both arguments are empty, a floating
point addition may overflow.  The resulting Float will then contain
either the value +infinity or -infinity (as appropriate according to IEC
559), and the resulting Exceptions part would have a value indicating
that an overflow has occurred.  (More commonly, a floating point
addition may be inexact, which can also be recorded as an exception in
this way.)  (Strict) arithmetic operations would then, trying to follow
the IEEE model, propagate the union of the arguments's exception
collections, adding any new exceptions that may arise from performing
the (IEEE) arithmetic operation on the Float parts of the arguments. 

                /kent k


Reply via email to