If I have a data type say:
data Color = Red | Yellow | Green
Is there a way I can turn this into a list of type [Color] getting all possibl
Surely delnan's answer is better. Since I do not know how to include a piece of code in a comment, I'll give a generalisation as a separate answer here.
allValues :: (Bounded a, Enum a) => [a]
allValues = [minBound..]
Now, this works for any type with a Bounded
and Enum
instance! And allColors
is just a special case:
allColors :: [Color]
allColors = allValues
In many cases, you won't even need to define allColors
separately.