7

Can a list be generated from a type's possible values? E.g.

data Shape = Circle | Rectangle | Triangle | Pentagon

to

[Circle,Rectangle,Triangle,Pentagon]

1
  • Yep it's a duplicate. This question should be closed. Commented Aug 14, 2013 at 13:01

1 Answer 1

20

Yes it can. It's a duty of Enum and Bounded type classes e.g.

λ data Shape = Circle | Rectangle | Triangle | Pentagon deriving (Show, Enum, Bounded)
λ [minBound .. maxBound] :: [Shape]
[Circle,Rectangle,Triangle,Pentagon]
λ [minBound ..] :: [Shape]
[Circle,Rectangle,Triangle,Pentagon]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.