By the way, tuples *can* be members of Enum if you make them so.
Try
instance (Enum a, Enum b, Bounded b) => Enum (a,b)
where
toEnum n = (a, b)
where a = toEnum (n `div` s)
b = toEnum (n `mod` s)
p = fromEnum (minBound `asTypeOf` b)
q = fromEnum (maxBound `asTypeOf` b)
s = q - p + 1
fromEnum (a, b) = fromEnum a * s + fromEnum b
where p = fromEnum (minBound `asTypeOf` b)
q = fromEnum (maxBound `asTypeOf` b)
s = q - p + 1
data T1 = A | B | C deriving (Enum, Eq, Bounded, Show)
data T2 = D | E | F deriving (Enum, Eq, Bounded, Show)
t1 = [(A,D) .. (B,F)]
I can't think of an approach that doesn't require all but one of
the tuple elements to have Bounded types. There are of course
all sorts of ways to enumerate tuples; this one is compatible
with the Ord instance.
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe