3 ms·
If you call it with argument 0 you get a runtime exception, because it results in a division by zero. It's "partial" because it's not defined for 0.
by the_af 6y ago
If you call it with argument 0 you get a runtime exception, because it results in a division by zero.
It's "partial" because it's not defined for 0.
- cies 6y agoSo it should have been: Double -> Maybe Double That would be the "right way" to fix this. (or create a type NotNilDouble, lol)
- bidirectional 6y agoOr, controversially, define 1/0 = 0.[1] [1]: https://www.hillelwayne.com/post/divide-by-zero/ https://www.hillelwayne.com/post/divide-by-zero/
- cies 6y agoEnough controversy in defining std libs as it is :)
- the_af 6y agoThe "right" way for division by zero is controversial, though maybe that would be a solution. It's clearer for partial function "head :: [a] -> a", which takes the first of a list if it exists, and explodes without dignity if the list is empty (this is what makes head partial). A proposal is "head :: [a] -> Maybe a", so head returns Nothing when the list is empty.
- cies 6y agoIdris does well here: https://www.idris-lang.org/docs/current/prelude_doc/docs/Prelude.List.html#Prelude.List.head https://www.idris-lang.org/docs/current/prelude_doc/docs/Pre...'
- cies 6y agoIdris does well here: https://www.idris-lang.org/docs/current/contrib_doc/docs/Data.Nat.html#Data.Nat.divMod https://www.idris-lang.org/docs/current/contrib_doc/docs/Dat...
- magicalhippo 6y agoIf Double is IEEE 754 compatible then it should be perfectly defined for 0, you'd get +/- infinity. There are algorithms which rely on this.
- deleted 6y ago[deleted]