[Haskell-cafe] Enum and Bounded in generic type

Robert Greayer robgreayer at yahoo.com
Tue Dec 30 12:45:36 EST 2008

Raeck said:

> Hi, how can I make the following code work? (show all the possible values of a type 'a')

>> showAll :: (Eq a, Bounded a, Enum a) => a -> [a]
>> showAll a = [minBound..maxBound]::[a]

What you are really looking for, I think, is a polymorphic value of type [a], where a is some enumerable, bounded type.

allValues :: (Enum a, Bounded a) => [a]
allValues = [minBound .. maxBound]

You can omit the type signature, but then you'll run into the monomorphism restriction (which you'll can turn off with, e.g. -XNoMonomorphismRestriction)


More information about the Haskell-Cafe mailing list