[Haskell-cafe] No Enum for (,), no Enum or Bounded for Either
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Fri Jun 1 19:52:35 UTC 2018
On Fri, Jun 01, 2018 at 03:47:47PM -0400, Viktor Dukhovni wrote:
> > On Jun 1, 2018, at 3:20 PM, Tom Ellis <tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk> wrote:
> > instance forall a b. (Bounded a, Bounded b, Enum a, Enum b) => Enum (E a b) where
> > fromEnum = \case
> > L a -> fromEnum a
> > R b -> fromEnum (maxBound :: a) + fromEnum b + 1
> This appears to assume that (fromEnum b) is never negative.
> (effectively that (minBound :: b) >= 0).
It assumes that minBound == 0, which we can see is wrong by considering Int.
> Ignoring overflow issues, this should perhaps be:
> R b -> fromEnum (maxBound :: a) + (fromEnum b - fromEnum (minBound :: b)) + 1
Yes, thanks, I think that's the kind of thing we want to do.
> This will of course overflow when ranges of a and/or b are large enough.
More information about the Haskell-Cafe