Re: Enum and bounded instances for (,) and Either

chessai <[email protected]>
Newsgroups gmane.comp.lang.haskell.libraries
Message-ID <CAD34_kK_3o5FcZU6y1jE=9qf67464zV3ma7n_uaRbp_2ykvM=Q@mail.gmail.com>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.