Thanks Michał,
I feel less confused as I realized the non-halting possibility per bottoms, from your hint.
I too think the signaling NaN is dreadful enough, so fortunately it's rarely seen nowadays.
> Note that due to the presence of @NaN@, not all elements of 'Float' have an additive inverse.
> Also note that due to the presence of -0, Float's 'Num' instance doesn't have an additive identity
> Note that due to the presence of @NaN@, not all elements of 'Float' have an multiplicative inverse.
So it should have been another family of `Num` classes, within which, various NaN related semantics can be legal, amongst which I'd think:
* Silent propagation of NaN in arithmetics, like `Maybe` monad does, seems quite acceptable
* Identity test, namely `NaN` /= `NaN` - this lacks theoretical ground or not?
* Comparison, neither `NaN` > 1 nor `NaN` <= 1 - whether or not there's a theoretical framework for this to hold? Maybe `Boolean` type needs enhancement too to do it?
No such family of `Num` classes exists to my aware by now, I just can't help wondering why.
Cheers,
Compl
Dear Yue,
Bottom has much weaker semantics than an exception: it means You may never get a result and thus will never handle it!
Another reason is convenience: it is frequently the case that giving NaN in a row of numbers is much more informative than crashing a program with an exception and never printing the result anyway.
Finally IEEE special values have clear propagation semantics: they are basically Maybe on steroids.
The problem with this approach is indeed a silent handling.
Never throw an error without telling exactly why it happened and exactly where to fix it :-). Using bottom is last resort; exceptions likewise.
--
Cheers
Michał