具有默认值的 Elm 类型别名
Elm type alias with default values
我有一个 "Block" 类型别名。
type alias Block = {x:Int, y:Int, color:String}
是否可以为 x、y 和颜色设置默认值?例如,我希望 x 和 y 默认为 0,颜色为 "blue".
您不能像在命令式语言中那样拥有默认值,但这不是问题,因为您可以轻松定义一个函数来设置所需的默认值:
defaultBlock : Block
defaultBlock = { x = 0, y = 0, color = "blue" }
我有一个 "Block" 类型别名。
type alias Block = {x:Int, y:Int, color:String}
是否可以为 x、y 和颜色设置默认值?例如,我希望 x 和 y 默认为 0,颜色为 "blue".
您不能像在命令式语言中那样拥有默认值,但这不是问题,因为您可以轻松定义一个函数来设置所需的默认值:
defaultBlock : Block
defaultBlock = { x = 0, y = 0, color = "blue" }