[Haskell-cafe] Why not some subclass of Floating to model NaNs as some handleable bottom?
Michal J Gajda
mgajda at mimuw.edu.pl
Wed Aug 4 13:11:05 UTC 2021
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.
But in order to fix this, it is better to add preconditions to
specific algorithms that do not allow IEEE special value on input
(`isFinite` or `isNotNaN`) and then track the origin of the special
value with the methods like those described here:
https://skillsmatter.com/skillscasts/14905-agile-functional-data-pipeline-in-haskell-a-case-study-of-multicloud-api-binding
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Ć
More information about the Haskell-Cafe
mailing list