具有默认值的Elm类型别名

C.S*_*lly 8 elm

我有一个"块"类型的别名.

type alias Block = {x:Int, y:Int, color:String}
Run Code Online (Sandbox Code Playgroud)

是否可以为x,y和颜色设置默认值?例如,我希望x和y默认为0,颜色为"蓝色".

Cha*_*ert 10

您不能像命令式语言那样拥有默认值,但这不是问题,因为您可以轻松定义设置所需默认值的函数:

defaultBlock : Block
defaultBlock = { x = 0, y = 0, color = "blue" }
Run Code Online (Sandbox Code Playgroud)