[Haskell-cafe] deriving instances of Enum for tuples of bounded, enumerable types (useful for generating QuickCheck.Arbitrary instances for collection of collection types)

Antoine Latter aslatter at gmail.com
Sun Mar 9 04:03:08 EDT 2008


On Sat, Mar 8, 2008 at 9:23 PM, Brandon S. Allbery KF8NH
>  I think you might be able to do this as a typeclass instead, at the
>  expense of having to insert an instance declaration for each type.
>  (You will have to use an extension if you want to declare instances
>  for types such as Int.  I think.)
>
>    class (Bounded a, Enum a) => BoundedEnum a where -- empty
>
>    instance BoundedEnum MyType a where
>    instance BoundedEnum Int where -- requires FlexibleInstances?

I've had good luck with things like:

class (Bounded a, Enum a) => BoundedEnum a
instance (Bounded a, Enum a) => BoundedEnum a

which picks up everything that can inhabit the new class.

-Antoine


More information about the Haskell-Cafe mailing list