Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可以从类型的可能值生成列表吗?例如
data Shape = Circle | Rectangle | Triangle | Pentagon
至
[Circle,Rectangle,Triangle,Pentagon]
是的,它可以。这是枚举和有界类型类的职责,例如
λ data Shape = Circle | Rectangle | Triangle | Pentagon deriving (Show, Enum, Bounded) λ [minBound .. maxBound] :: [Shape] [Circle,Rectangle,Triangle,Pentagon] λ [minBound ..] :: [Shape] [Circle,Rectangle,Triangle,Pentagon]