Re: Enum and bounded instances for (,) and Either
chessai <[email protected]>
| Newsgroups | gmane.comp.lang.haskell.libraries |
|---|---|
| Message-ID | <CAD34_k+QUUuBaM5Zh6Kx3Rb_QgySH_fimsTMZuryHkeObpAF8A@mail.gmail.com> |
Note that it is probably just missing some `error` calls in the right place. On Wed, May 12, 2021, 13:27 chessai <[email protected]> wrote: > I am +1 on these instances existing, but I just discovered via > quickcheck-classes that the given code does not uphold succ-pred or > pred-succ identity: > > ``` > Enum: Succ Pred Identity *** Failed! Falsified (after 2 tests): > Description: succ (pred x) = x > a = (0,1) > succ (pred x) = (-1,1) > Enum: Pred Succ Identity *** Failed! Falsified (after 1 test): > Description: pred (succ x) = x > a = (0,0) > pred (succ x) = (1,0) > *** Failed! Falsified (after 2 tests).. > Enum: Succ Pred Identity *** Failed! Falsified (after 2 tests): > Description: succ (pred x) = x > a = Left 0 > succ (pred x) = Right (-9223372036854775808) > Enum: Pred Succ Identity *** Failed! Falsified (after 1 test): > Description: pred (succ x) = x > a = Left 0 > pred (succ x) = Right (-9223372036854775808) > ``` > > Perhaps this is indicative of something wrong with the proposed instance? > > Thanks > > On Wed, May 12, 2021 at 11:01 AM Henning Thielemann > <[email protected]> wrote: > > > > > > On Wed, 12 May 2021, Sandy Maguire wrote: > > > > > Found myself puzzled the other day when I wanted an (Enum a, Enum b) => > > > Enum (a, b) instance, and was distraught that it didn't exist. > > > > > > The following is a reasonable implementation: > > > > This is certainly an instance that fulfills some laws, but do we really > > want it or is it more likely an accident if someone writes, say, succ > > (a,b)? > > > > We already allow "max (a,b) (c,d)", which can be pretty counterintuitive. > > I think the Ord instance for pairs is currently mostly used for Set and > > Map, but a separate class for this purpose would have been better. > > _______________________________________________ > > Libraries mailing list > > [email protected] > > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries > _______________________________________________ Libraries mailing list [email protected] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries