Bounded whole
- Dominant language
- Haskell
- Stars
- 27
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Description
Right now we have `whole :: Fractional a => Interval a` that divides by zero. This is useful for floating point types. It's not helpful for `Rational` where it produces an error, and the type doesn't even work for things like `Int` or `Weekday`.
`whole' :: Bounded a => Interval a` seems like a nice thing. But it leaves code that deals polymorphically with intervals (like the interval package itself) in a bad place because there is no way to get at the appropriate whole without knowing in advance what your `a` is like.
What is your opinion on this old mailing list thread? http://www.haskell.org/pipermail/haskell/2005-March/thread.html#15490, and especially here where this exact application for intervals is discussed: http://www.haskell.org/pipermail/haskell/2005-March/015510.html
It seems to me that `Float` is just as `Bounded` as `Int` is. The bounds are infinity if the floating point type has it and the max representable float otherwise. Maybe the intervals package should come with the instances for now, in a submodule that you have to import explicitly? Even then it seems like a slightly hostile thing to do, though.
The `Fractional` instance for non empty intervals would acquire a `Bounded` context, which is problematic for `Rational` but does also represent an actual problem with using that instance, which is to say the functions that you wouldn't be able to call are functions that currently can result in "Exception: Ratio has zero denominator." It might be possible to avoid this context by changing the `Fractional` instance implementation so it doesn't refer to `whole` but instead just does the divisions by zero there, thereby letting the `Fractional a` instance decide if it has `Infinity` or not. Tradeoff is `(1 :: Int ... 2) / (-1 ... 1)` would become an exception instead of `whole' :: Interval Int` but that doesn't seem important.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.