
I have some questions about how Haskell's numeric classes might be revamped. Is it possible in Haskell to circumscribe the availability of certain "unsafe" numeric operations such as div, /, mod? If this is not possible already, could perhaps a compiler flag "-noUnsafeDivide" could be added to make such a restriction? What I have in mind is to remove division by zero as an untypable expression. The idea is to require div, /, mod to take NonZeroNumeric values in their second argument. NonZeroNumeric values could be created by functions of type: Number a => a -> Maybe NonZeroNumeric or something similar. Has this been tried and failed? I'm curious as to what problems there might be with such an approach. --PeterD

Wed, 7 Feb 2001 16:17:38 -0500, Peter Douglass
What I have in mind is to remove division by zero as an untypable expression. The idea is to require div, /, mod to take NonZeroNumeric values in their second argument. NonZeroNumeric values could be created by functions of type: Number a => a -> Maybe NonZeroNumeric or something similar.
IMHO it would be impractical. Often I know that the value is non-zero, but it is not statically determined, so it would just require uglification by doing that conversion and then coercing Maybe NonZeroNumeric to NonZeroNumeric. It's bottom anyway when the value is 0, but bottom would come from Maybe coercion instead of from quot, so it only gives a worse error message. It's so easy to define partial functions that it would not buy much for making it explicit outside quot. Haskell does not have subtypes so a coercion from NonZeroNumeric to plain Numbers would have to be explicit as well, even if logically it's just an injection. Everybody assumes that quot has a symmetric type as in all other languages, but in your proposal quot's arguments come from completely disjoint worlds. Moreover, 1/0 is defined on IEEE Doubles (e.g. in ghc): infinity. -- __("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZASTÊPCZA QRCZAK
participants (2)
-
Peter Douglass
-
qrczak@knm.org.pl