Is it possible to create a list of possible data types in Haskell?

Is it possible to create a list of possible type values? For example.

data Shape = Circle | Rectangle | Triangle | Pentagon

to

[Circle,Rectangle,Triangle,Pentagon]

+7
types haskell list-comprehension
source share
1 answer

Yes maybe. These are duty of Enum and Bounded type classes, for example

 λ data Shape = Circle | Rectangle | Triangle | Pentagon deriving (Show, Enum, Bounded) λ [minBound .. maxBound] :: [Shape] [Circle,Rectangle,Triangle,Pentagon] λ [minBound ..] :: [Shape] [Circle,Rectangle,Triangle,Pentagon] 
+20
source share

All Articles