[Haskell-cafe] No Enum for (,), no Enum or Bounded for Either
ietf-dane at dukhovni.org
Fri Jun 1 19:47:47 UTC 2018
> 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).
Ignoring overflow issues, this should perhaps be:
R b -> fromEnum (maxBound :: a) + (fromEnum b - fromEnum (minBound :: b)) + 1
This will of course overflow when ranges of a and/or b are large enough.
More information about the Haskell-Cafe