We can write
instance Bounded a => Bounded (Maybe a) where minBound = Nothing maxBound = Just maxBound instance (Bounded a, Bounded b) => Bounded (Either a b) where minBound = Left minBound maxBound = Right maxBound While Bounded intentionally does not have an Ord superclass, I think it's worth mentioning that these are the instances that arise naturally from the Ord instances for the types in question. _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
Clever. I'm surprised those instances weren't already there. On Mon, May 7, 2018 at 11:19 PM, David Feuer <[hidden email]> wrote:
_______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
In reply to this post by David Feuer
On 8 May 2018 at 13:19, David Feuer <[hidden email]> wrote:
> We can write > > instance Bounded a => Bounded (Maybe a) where > minBound = Nothing > maxBound = Just maxBound > > instance (Bounded a, Bounded b) => Bounded (Either a b) where > minBound = Left minBound > maxBound = Right maxBound > > While Bounded intentionally does not have an Ord superclass, I think it's > worth mentioning that these are the instances that arise naturally from the > Ord instances for the types in question. Except these may be surprising to people; e.g. someone may expect that `minBound = Right minBound` as well. Though as Maybe and Either don't have Enum instances this may be less of an issue. -- Ivan Lazar Miljenovic [hidden email] http://IvanMiljenovic.wordpress.com _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
On May 8, 2018 at 1:06:24 AM, Ivan Lazar Miljenovic ([hidden email]) wrote:
Good point — while we’re at it, we should add the Enum instances as well :-) Cheers, Gershom _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
On 8 May 2018 at 15:26, Gershom B <[hidden email]> wrote:
> On May 8, 2018 at 1:06:24 AM, Ivan Lazar Miljenovic > ([hidden email]) wrote: > > > Except these may be surprising to people; e.g. someone may expect that > `minBound = Right minBound` as well. Though as Maybe and Either don't > have Enum instances this may be less of an issue. > > > Good point — while we’re at it, we should add the Enum instances as well :-) In that case... when do you switch over from Left to Right? -- Ivan Lazar Miljenovic [hidden email] http://IvanMiljenovic.wordpress.com _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
On Tue, 8 May 2018, Ivan Lazar Miljenovic wrote: > On 8 May 2018 at 15:26, Gershom B <[hidden email]> wrote: > >> Good point — while we’re at it, we should add the Enum instances as well :-) > > In that case... when do you switch over from Left to Right? I guess when Left maxBound is reached. :-) _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
In reply to this post by Ivan Lazar Miljenovic
minBound = Left minBound <= Left a < Right b <= Right maxBound = maxBound fits with the behavior of the existing Ord instance. On the other hand, Left (), being strictly less than minBound would rather drastically undermine the expected interaction of Ord and Bounded. -Edward On Tue, May 8, 2018 at 1:06 AM, Ivan Lazar Miljenovic <[hidden email]> wrote:
_______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
On 9 May 2018 at 12:15, Edward Kmett <[hidden email]> wrote:
> minBound = Left minBound <= Left a < Right b <= Right maxBound = maxBound > > fits with the behavior of the existing Ord instance. > > On the other hand, Left (), being strictly less than minBound would rather > drastically undermine the expected interaction of Ord and Bounded. Fair enough. I had also missed in David's initial proposal that we had Bounded on both a and b in (Either a b). I'm +1 on these instances (more from a "they're the logical instances" PoV than "this will be useful"). -- Ivan Lazar Miljenovic [hidden email] http://IvanMiljenovic.wordpress.com _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
Free forum by Nabble | Edit this page |