Add instance Bounded (Ratio a)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Add instance Bounded (Ratio a)

Dannyu NDos
instance (Integral a, Bounded a) => Bounded (Ratio a) where
    minBound = minBound % 1
    maxBound = maxBound % 1

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Add instance Bounded (Ratio a)

Vanessa McHale

Seems sensible. Out of curiosity, what would this help with?

On 6/14/19 6:44 PM, Dannyu NDos wrote:
instance (Integral a, Bounded a) => Bounded (Ratio a) where
    minBound = minBound % 1
    maxBound = maxBound % 1

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Add instance Bounded (Ratio a)

Eric Mertens
Ratio only only generally be used with Integer, which isn’t itself an instance of Bounded. This probably wouldn’t be a very useful instance. It has overflow issues with Bounded types like Int for various operations including comparisons.

On Jun 16, 2019, at 10:14 AM, Vanessa McHale <[hidden email]> wrote:

Signed PGP part

Seems sensible. Out of curiosity, what would this help with?

On 6/14/19 6:44 PM, Dannyu NDos wrote:
instance (Integral a, Bounded a) => Bounded (Ratio a) where
    minBound = minBound % 1
    maxBound = maxBound % 1

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries



_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Add instance Bounded (Ratio a)

David Feuer
Agreed. Moreover, even if we had some magical way to avoid overflow issues, there's no guarantee that

  maxBound % 1 >= minBound % (-1)

or that

  minBound % 1 <= maxBound % (-1)

So I think this is fundamentally doomed.

On Sun, Jun 16, 2019, 2:30 PM Eric Mertens <[hidden email]> wrote:
Ratio only only generally be used with Integer, which isn’t itself an instance of Bounded. This probably wouldn’t be a very useful instance. It has overflow issues with Bounded types like Int for various operations including comparisons.

On Jun 16, 2019, at 10:14 AM, Vanessa McHale <[hidden email]> wrote:

Signed PGP part

Seems sensible. Out of curiosity, what would this help with?

On 6/14/19 6:44 PM, Dannyu NDos wrote:
instance (Integral a, Bounded a) => Bounded (Ratio a) where
    minBound = minBound % 1
    maxBound = maxBound % 1

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Add instance Bounded (Ratio a)

David Feuer
Sorry, agreed with one caveat. Ratio Natural is also perfectly sensible.

On Sun, Jun 16, 2019, 2:49 PM David Feuer <[hidden email]> wrote:
Agreed. Moreover, even if we had some magical way to avoid overflow issues, there's no guarantee that

  maxBound % 1 >= minBound % (-1)

or that

  minBound % 1 <= maxBound % (-1)

So I think this is fundamentally doomed.

On Sun, Jun 16, 2019, 2:30 PM Eric Mertens <[hidden email]> wrote:
Ratio only only generally be used with Integer, which isn’t itself an instance of Bounded. This probably wouldn’t be a very useful instance. It has overflow issues with Bounded types like Int for various operations including comparisons.

On Jun 16, 2019, at 10:14 AM, Vanessa McHale <[hidden email]> wrote:

Signed PGP part

Seems sensible. Out of curiosity, what would this help with?

On 6/14/19 6:44 PM, Dannyu NDos wrote:
instance (Integral a, Bounded a) => Bounded (Ratio a) where
    minBound = minBound % 1
    maxBound = maxBound % 1

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries