Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
228 views
in Technique[技术] by (71.8m points)

Getting a list of all possible data type values in Haskell

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 possible values? [Red, Yellow, Green]

Perhaps this is a complete anti pattern?

question from:https://stackoverflow.com/questions/4299319/getting-a-list-of-all-possible-data-type-values-in-haskell

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
data Color = Red
           | Yellow
           | Green
           deriving Enum

allColors = [Red ..]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...