Re:Haskell: The Bad Parts, part 2 (2020)
by magicalhippo on Tuesday February 09, 2021 @05:19PM
(#26083170)
If Double is IEEE 754 compatible then it should be perfectly defined for 0, you'd get +/- infinity. There are algorithms which rely on this.
So it should have been: Double -> Maybe Double
That would be the "right way" to fix this.
(or create a type NotNilDouble, lol)
Re:Haskell: The Bad Parts, part 2 (2020)
by bidirectional on Tuesday February 09, 2021 @02:00PM
(#26081258)
Or, controversially, define 1/0 = 0.[1]
Enough controversy in defining std libs as it is :)
Re:Haskell: The Bad Parts, part 2 (2020)
by the_af on Tuesday February 09, 2021 @03:11PM
(#26081897)
The "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.
Re:Haskell: The Bad Parts, part 2 (2020)
by cies on Wednesday February 10, 2021 @06:04AM
(#26087721)
Idris does well here:
https://www.idris-lang.org/docs/current/prelude_doc/docs/Pre...'
Re:Haskell: The Bad Parts, part 2 (2020)
by cies on Wednesday February 10, 2021 @06:06AM
(#26087733)
Idris does well here:
https://www.idris-lang.org/docs/current/contrib_doc/docs/Dat...
It's "partial" because it's not defined for 0.