I would like to know if there is a way to make GHC automatically derive the instance of integral from a data type of the form :
data = A | B | C | D
so that fromIntegral A = 0, fromIntegral B = 1, etc. ?
Using
data MyType = A | B | C | D deriving (Show, Eq, Ord, Enum, Real, Integral)
produce the error
Can't make a derived instance of ‘Integral MyType’: ‘Integral’ is not a derivable class
In the data declaration for ‘MyType’
(even with the extension GeneralizedNewtypeDeriving)