2
我试图按照Model the problem文章中的指导原则在Elm中创建调色板类型。我的第一个想法是说:需要帮助建模调色板类型
type alias Palette = List Color
但这有缺点。调色板是一系列颜色,但它也必须有两种颜色,一种用于背景,一种用于前景。
我的第二次尝试是有一个记录类型:
type alias Palette =
{ bg : Color
, fg : List Color
}
这是更好,但我如何确保fg
场有至少一个元素的列表?
任何提示如何功能考虑和make illegal states unrepresentable?
谢谢!