
1 Jun
2018
1 Jun
'18
3:52 p.m.
On Fri, Jun 01, 2018 at 03:47:47PM -0400, Viktor Dukhovni wrote:
On Jun 1, 2018, at 3:20 PM, Tom Ellis
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.
Naturally.