Enum and bounded instances for (,) and Either

chessai chessai1996 at gmail.com
Wed May 12 18:27:58 UTC 2021


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
<lemming at henning-thielemann.de> 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
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


More information about the Libraries mailing list