Section 6.3.4 of the Haskell 98 report says

  "Instances of Enum may be derived for any enumeration type (types
  whose constructors have no fields).  There are also Enum instances
  for floats."


A consequence of this is that an Enum dictionary *cannot* be derived
for:

  data MyInt = MyInt Int
    {- deriving Enum -}

I find this a little surprising.  In general, any algebraic datatype
satisfying the conditions in Appendix D of the report should be
enumerable, using the same lexicographic ordering used in D.1 for Eq
and Ord.  Thus MyInt has the obvious Enum instance, and

data Foo = X | Y | Z
data Bar = A Foo | B Foo | C Foo

main = print (enumFrom (toEnum 0) :: [Bar])

yields

[A X, A Y, A Z,
 B X, B Y, B Z,
 C X, C Y, C Z]

Any problems with this?

--KW 8-)


Reply via email to