Can a list be generated from a type's possible values? E.g.
data Shape = Circle | Rectangle | Triangle | Pentagon
to
[Circle,Rectangle,Triangle,Pentagon]
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With