|
|
|
|
|
by throwaway183839
4117 days ago
|
|
> It feels a little redundant to have to manually list out all the elements when the information is known statically, and updating the list will be necessary if the Peg type changes. In Racket, writing a macro for this would be trivial, but alas, this is Haskell. Perhaps there is a way, I’m just not aware of it. A reasonably clean way would be to define data Color = Red | Green | Blue | Yellow | Orange | Purple
deriving (Enum, Bounded, Show)
and then (e.g. in ghci) you can do >> [minBound .. maxBound] :: [Color]
[Red,Green,Blue,Yellow,Orange,Purple]
I often define the useful function enumerate :: (Enum a, Bounded a) => [a]
enumerate = [minBound .. maxBound]
for exactly this purpose. |
|